快速入门:使用 Azure 逻辑应用创建第一个工作流 - Azure 门户Quickstart: Create your first workflow by using Azure Logic Apps - Azure portal

本快速入门介绍了使用 Azure 逻辑应用构建第一个工作流背后的通用基本概念,例如创建空白逻辑应用、添加触发器和操作及测试逻辑应用。This quickstart introduces the basic general concepts behind how to build your first workflow by using Azure Logic Apps, such as creating a blank logic app, adding a trigger and an action, and then testing your logic app. 在本快速入门中,构建一个逻辑应用,以便定期查看网站的 RSS 源中是否有新项。In this quickstart, you build a logic app that regularly checks a website's RSS feed for new items. 如果存在新项,逻辑应用会针对每个项发送电子邮件。If new items exist, the logic app sends an email for each item. 完成后,逻辑应用看起来大致与以下工作流类似:When you're done, your logic app looks like this workflow at a high level:

高级示例逻辑应用工作流

对于此方案,你需要一个 Azure 订阅或注册一个 Azure 试用帐户,并需要一个由 Azure 逻辑应用支持的服务(例如 Office 365 Outlook、Outlook.com 或 Gmail)提供的电子邮件帐户。For this scenario, you need an Azure subscription or sign up for a trial Azure account, an email account from a service that's supported by Azure Logic Apps, such as Office 365 Outlook, Outlook.com, or Gmail. 如需其他受支持的电子邮件服务,请在这里查看连接器列表For other supported email services, review the connectors list here. 在此示例中,逻辑应用使用 Office 365 Outlook 帐户。In this example, the logic app uses an Office 365 Outlook account. 如果使用其他电子邮件服务,则总体常规步骤相同,但用户界面可能略有不同。If you use a different email service, the overall general steps are the same, but your user interface might differ slightly.

登录到 Azure 门户Sign in to the Azure portal

使用 Azure 帐户凭据登录到 Azure 门户Sign in to the Azure portal with your Azure account credentials.

创建逻辑应用Create your logic app

  1. 在 Azure 主页上的搜索框中,查找并选择“逻辑应用”。From the Azure home page, in the search box, find and select Logic Apps.

    查找并选择“逻辑应用”

  2. 在“逻辑应用”页上,选择“添加” 。On the Logic Apps page, select Add.

    添加新逻辑应用

  3. 在“逻辑应用”窗格上,提供有关逻辑应用的详细信息,如下所示。On the Logic App pane, provide details about your logic app as shown below. 完成后,选择“创建”。After you're done, select Create.

    提供有关新逻辑应用的详细信息

    属性Property ValueValue 说明Description
    名称Name <logic-app-name><logic-app-name> 逻辑应用名称,只能包含字母、数字、连字符 (-)、下划线 (_)、括号(())和句点 (.)。Your logic app name, which can contain only letters, numbers, hyphens (-), underscores (_), parentheses ((, )), and periods (.). 此示例使用“My-First-Logic-App”。This example uses "My-First-Logic-App".

    注意:逻辑应用的名称必须在区域之间是唯一的。Note: Names for logic apps must be unique across regions.

    订阅Subscription <Azure-subscription-name><Azure-subscription-name> Azure 订阅名称Your Azure subscription name
    资源组Resource group <Azure-resource-group-name><Azure-resource-group-name> 用于组织相关资源的 Azure 资源组的名称。The name for the Azure resource group used to organize related resources. 此示例使用“My-First-LA-RG”。This example uses "My-First-LA-RG".

    注意:资源组的名称必须在区域之间是唯一的。Note: Names for resource groups must be unique across regions.

    位置Location <Azure-region><Azure-region> 用于存储逻辑应用信息的区域。The region where to store your logic app information. 此示例使用“中国北部”。This example uses "China North".
    Log AnalyticsLog Analytics 关闭Off 对于诊断日志记录,请保留“关闭”设置。Keep the Off setting for diagnostic logging.
  4. 在 Azure 部署你的应用后,在 Azure 工具栏上,选择“通知” > “转到资源”,查看你部署的逻辑应用。After Azure deploys your app, on the Azure toolbar, select Notifications > Go to resource for your deployed logic app.

    转到新创建的逻辑应用资源

    或者,可以通过在搜索框中键入名称来查找和选择逻辑应用。Or, you can find and select your logic app by typing the name in the search box.

    逻辑应用设计器打开并显示一个包含简介视频和常用触发器的页面。The Logic Apps Designer opens and shows a page with an introduction video and commonly used triggers. 在“模板”下选择“空白逻辑应用”。Under Templates, select Blank Logic App.

    选择逻辑应用的空白模板

接下来请添加一个触发器,该触发器在出现新的 RSS 源项时触发。Next, add a trigger that fires when a new RSS feed item appears. 每个逻辑应用都必须从触发器开始,该触发器在发生特定事件或特定条件得到满足的情况下触发。Every logic app must start with a trigger, which fires when a specific event happens or when a specific condition is met. 每当触发器触发时,Azure 逻辑应用引擎就会创建一个逻辑应用实例来启动并运行工作流。Each time the trigger fires, the Azure Logic Apps engine creates a logic app instance that starts and runs your workflow.

添加 RSS 触发器Add the RSS trigger

  1. 在“逻辑应用设计器”的搜索框下,选择“全部” 。In the Logic App Designer, under the search box, select All.

  2. 在搜索框中,输入 rss 以查找 RSS 连接器。In the search box, enter rss to find the RSS connector. 从触发器列表中,选择“发布源项时”触发器。From the triggers list, select the When a feed item is published trigger.

    选择“发布源项时”触发器

  3. 为触发器提供如下表所述的信息:Provide the information for your trigger as described in the table:

    使用 RSS 源、频率和间隔设置触发器

    属性Property ValueValue 说明Description
    RSS 源 URLThe RSS feed URL <RSS-feed-URL><RSS-feed-URL> 要监视的 RSS 源的链接。The link for the RSS feed that you want to monitor. 本示例使用 http://feeds.reuters.com/reuters/topNewsThis example uses http://feeds.reuters.com/reuters/topNews.
    时间间隔Interval 11 在两次检查之间需等待的时间间隔数The number of intervals to wait between checks
    频率Frequency MinuteMinute 两次检查的间隔的时间单位The unit of time for each interval between checks

    时间间隔和频率合在一起,即可定义逻辑应用的触发器的计划。Together, the interval and frequency define the schedule for your logic app's trigger. 此逻辑应用每分钟检查一次源。This logic app checks the feed every minute.

  4. 若要暂时折叠触发器详细信息,请单击触发器的标题栏。To collapse the trigger details for now, click inside the trigger's title bar.

    折叠逻辑应用形状即可隐藏详细信息

  5. 保存逻辑应用。Save your logic app. 在设计器工具栏上选择“保存”。On the designer toolbar, select Save.

逻辑应用现已生成,但除了检查 RSS 源,不能执行任何操作。Your logic app is now live but doesn't do anything other than check the RSS feed. 因此,请添加一项在触发器触发时进行响应的操作。So, add an action that responds when the trigger fires.

添加“发送电子邮件”操作Add the "send email" action

现在请添加一项操作,在 RSS 源中出现新项时发送电子邮件。Now add an action that sends an email when a new item appears in the RSS feed.

  1. 在“发布源项时”触发器下,选择“新建步骤” 。Under the When a feed item is published trigger, select New step.

    在触发器下,选择“新建步骤”

  2. 在“选择操作”和搜索框下,选择“全部” 。Under Choose an action and the search box, select All.

  3. 在搜索框中,输入 send an email 以查找提供此操作的连接器。In the search box, enter send an email to find connectors that offer this action. 从操作列表中,为要使用的电子邮件服务选择“发送电子邮件”操作。From the actions list, select the "send an email" action for the email service that you want to use. 此示例使用 Office 365 Outlook 连接器,该连接器具有“发送电子邮件”操作。This example uses the Office 365 Outlook connector, which has the Send an email action.

    选择 Office 365 Outlook 的“发送电子邮件”操作

    若要通过对操作列表进行筛选来查找特定的应用或服务,可以先选择应用或服务:To filter the actions list to a specific app or service, you can select that app or service first:

    • 对于 Azure 工作或学校帐户,请选择“Office 365 Outlook”。For Azure work or school accounts, select Office 365 Outlook.
    • 对于个人 Microsoft 帐户,请选择“Outlook.com”。For personal Microsoft accounts, select Outlook.com.
  4. 如果你选择的电子邮件连接器提示你进行身份验证,请立即完成该步骤,以在逻辑应用与电子邮件服务之间创建连接。If your selected email connector prompts you to authenticate your identity, complete that step now to create a connection between your logic app and your email service.

    备注

    在此特定示例中,你将手动进行身份验证。In this specific example, you manually authenticate your identity. 但是,要求进行身份验证的各种连接器所支持的身份验证类型有所不同。However, connectors that require authentication differ in the authentication types that they support. 你也可以选择设置要用于处理身份验证的方式。You also have options to set up the way that you want to handle authentication. 例如,当使用 Azure 资源管理器模板进行部署时,可以对你想要经常或轻松更改的输入(如连接信息)进行参数化并提高安全性。For example, when you use Azure Resource Manager templates for deployment, you can parameterize and improve security on inputs that you want to change often or easily, such as connection information. 有关详细信息,请参阅以下主题:For more information, see these topics:

  5. 在“发送电子邮件”操作中,指定需要电子邮件包括的数据。In the Send an email action, specify the data that you want the email to include.

    1. 在“收件人”框中,输入收件人的电子邮件地址。In the To box, enter the recipient's email address. 为进行测试,可以使用你的电子邮件地址。For testing purposes, you can use your email address.

      现在,请忽略出现的“添加动态内容”列表。For now, ignore the Add dynamic content list that appears. 单击某些编辑框时,此列表会出现并显示前一步骤中提供的参数,这样即可将其作为工作流的输入包括进去。When you click inside some edit boxes, this list appears and shows any available parameters from the previous step that you can include as inputs in your workflow.

    2. 在“主题”框中,输入带有尾随空格的以下文本:New RSS item: In the Subject box, enter this text with a trailing blank space: New RSS item:

      在“主题”属性中,输入电子邮件主题

    3. 从“添加动态内容”列表中选择“源标题”,用于包括 RSS 项标题。From the Add dynamic content list, select Feed title to include the RSS item title.

      从动态内容列表中,选择“源标题”属性

      完成后,电子邮件主题如以下示例所示:When you're done, the email subject looks like this example:

      完成的添加源标题的电子邮件主题示例

      如果“For each”循环显示在设计器上,则你为数组选择了一个令牌,例如 categories-Item 令牌。If a "For each" loop appears on the designer, then you selected a token for an array, for example, the categories-Item token. 对于这些类型的令牌,设计器会自动围绕引用该令牌的操作添加此循环。For these kinds of tokens, the designer automatically adds this loop around the action that references that token. 这样一来,逻辑应用会对每个数组项执行同一操作。That way, your logic app performs the same action on each array item. 若要删除循环,请选择循环的标题栏上的省略号 ( ... ),然后选择“删除”。 To remove the loop, select the ellipses (...) on the loop's title bar, then select Delete.

    4. 在“正文”框中选择此文本,然后选择这些令牌作为电子邮件正文。In the Body box, enter this text, and select these tokens for the email body. 若要在编辑框中添加空行,请按 Shift + Enter。To add blank lines in an edit box, press Shift + Enter.

      选择电子邮件正文内容的属性

      属性Property 说明Description
      源标题Feed title 项的标题The item's title
      源发布日期Feed published on 项的发布日期和时间The item's publishing date and time
      源主链接Primary feed link 项的 URLThe URL for the item
  6. 保存逻辑应用。Save your logic app.

接下来,测试逻辑应用。Next, test your logic app.

运行逻辑应用Run your logic app

若要手动启动逻辑应用,请在设计器工具栏中选择“运行”。To manually start your logic app, on the designer toolbar bar, select Run. 或者,等待逻辑应用根据指定的计划(每隔一分钟)检索 RSS 源。Or, wait for your logic app to check the RSS feed based on your specified schedule (every minute). 如果 RSS 源有新项,逻辑应用会为每个新项发送一封电子邮件。If the RSS feed has new items, your logic app sends an email for each new item. 否则,逻辑应用会等到下一个间隔过后才进行检查。Otherwise, your logic app waits until the next interval before checking again. 如果没有收到任何电子邮件,请检查垃圾邮件文件夹。If you don't get any emails, check your junk email folder.

例如,下面是此逻辑应用发送的一封示例电子邮件。For example, here is a sample email that this logic app sends.

出现新的 RSS 源项时发送的示例电子邮件

从技术上讲,当触发器检查 RSS 源并找到新项时,触发器将会激发,并且 Azure 逻辑应用引擎会创建一个逻辑应用工作流实例,用于运行工作流中的操作。Technically, when the trigger checks the RSS feed and finds new items, the trigger fires, and the Azure Logic Apps engine creates an instance of your logic app workflow that runs the actions in the workflow. 如果触发器未找到新项,则触发器不会激发,而是“跳过”实例化工作流的操作。If the trigger doesn't find new items, the trigger doesn't fire and "skips" instantiating the workflow.

祝贺你,现已使用 Azure 门户成功生成并运行了第一个逻辑应用。Congratulations, you've now successfully built and run your first logic app with the Azure portal.

清理资源Clean up resources

不再需要此示例时,删除包含你的逻辑应用和相关资源的资源组。When you no longer need this sample, delete the resource group that contains your logic app and related resources.

  1. 在 Azure 主菜单中,选择“资源组”,然后选择逻辑应用的资源组。On the main Azure menu, select Resource groups, and then select your logic app's resource group. 在“概述”窗格上,选择“删除资源组”。On the Overview pane, select Delete resource group.

    查找、选择和删除资源组

  2. 出现确认窗格时,输入资源组名称,然后选择“删除”。When the confirmation pane appears, enter the resource group name, and select Delete.

    若要确认删除,请选择“删除”

备注

删除逻辑应用后,任何新运行都不会实例化。When you delete a logic app, no new runs are instantiated. 所有正在进行和挂起的运行都将取消。All in-progress and pending runs are canceled. 如果有成千上万个运行,取消操作可能需要很长时间才能完成。If you have thousands of runs, cancellation might take significant time to complete.