使用 Azure 逻辑应用设计工作流

已完成

实现业务流程可能困难,因为需要使不同的服务协同工作。 想一想公司用于存储和处理数据的所有服务:Salesforce、Office 365、Oracle、X、YouTube、Dropbox、Google 服务、Azure AI 服务等。 如何集成所有这些产品?

Azure 逻辑应用提供了数百个预构建的连接器,这些连接器可与各种应用、数据、服务和系统以及其他组件配合使用,以将所有内容组织并集成到工作流中。 例如,在这个运动鞋公司的方案中,我们希望监测社交媒体对我们新篮球鞋产品的反应。 我们将构建一个逻辑应用工作流来集成 X、Azure AI 服务、SQL Server 和 Outlook 电子邮件。

在本单元中,我们将规划实现业务流程所需的步骤顺序。 然后,我们会将这些步骤映射到 Azure 逻辑应用中可用的组件。 最后,我们将使用 Azure 逻辑应用中的设计器将这些部分组合到工作流中。 下图显示了此应用开发过程的概述。

Diagram showing the typical sequence of activities to create a logic app workflow. The process has five steps. First, plan your business process. Second, identify the type for each step in your process. Third, decide which component will implement each step. Fourth, use the designer to build your workflow from the components. Fifth, save your design. Your logic app workflow will now run automatically in the cloud.

以下各部分分别介绍了应用开发过程中的这五个步骤:

规划业务流程

创建逻辑应用工作流的第一步是规划业务流程的步骤。 在社交媒体监视场景中,步骤如下:

  • 检测有关产品的推文
  • 分析情绪
  • 存储正面推文的链接
  • 通过电子邮件向客户服务发送负面推文

通常,可以使用流程图来捕获流程步骤。 下图显示了社交媒体监视应用的流程图。

Diagram showing a flowchart for the way the fictional shoe company processes tweets written about their product.

确定流程中每个步骤的类型

业务流程的各个步骤执行不同类型的操作。 一部分响应外部事件、一部分处理或存储数据,另一部分基于数据做出决策。 Azure 逻辑应用对这三个类别使用术语“触发器”、“操作”和“控制操作”。

例如,在我们的社交媒体监视场景中,“触发器”在发布新推文时启动流程,“操作”执行分析情绪等任务,“控制操作”根据情绪分数做出决策。 下图显示了社交媒体监视应用中每个步骤的类型。

Diagram showing the flowchart for the shoe company social media monitoring app. Each step is labeled as a trigger, action, or control action.

将步骤映射到组件

若要确定要实现的预建组件,需要清楚了解组件类型。 让我们更正式地了解组件类型的定义:

  • 触发器是在满足特定条件时发生的事件。 如果条件合适(例如计时器过期或数据变为可用时),触发器将自动激活。 每个工作流必须以触发器开头。 在本示例中,我们希望在新推文提及我们的产品时触发工作流。

  • 操作是在业务流程中运行任务之一的操作。 当触发器激活或其他操作完成时,操作会运行。 我们的社交媒体监视应用有三项操作:分析情绪、插入数据库行和发送电子邮件。

  • 控制操作是特殊的内置操作,可为工作流添加决策和循环。 示例使用控制操作根据情绪评分进行分支。

连接器是一组相关的触发器和操作。 从概念上讲,可将连接器视为可访问服务或系统的组件。 例如,X 连接器可以发送和接收推文,而 Microsoft 365 Outlook 连接器可以管理电子邮件、日历和联系人。 下图显示了 X 连接器,其操作分为两类。

Diagram showing the triggers and actions available in the X connector.

现在,需要将流程图中的每个任务映射到 Azure 逻辑应用中可用的触发器和操作。 下图显示了我们在社交媒体应用中使用的连接器,并突出显示了相关的触发器和操作。

Diagram showing the operations available in the connectors used by the social media monitoring app. Specifically, the connectors are X, Text Analytics, SQL Server, and Office 365 Outlook along with a graphical representation for each control action. The trigger and actions used in the social media monitoring app are highlighted.

使用设计器定义工作流

Azure 逻辑应用中的设计器是用于创建工作流的图形工具。 可以从包含可在工作流中使用的触发器和操作的连接器库中进行选择。 可使用设计器来安排触发器、操作和控制操作。 下面的屏幕截图显示了包含已完成工作流的设计器。

Screenshot showing the workflow designer with the completed social media monitoring app. The workflow starts with the X trigger, which is followed by three actions: detect sentiment, insert row, and send email. A control action determines whether the insert row or send email action executes based on the score of the **Detect sentiment** action.

保存工作流后,逻辑应用将自动实时发布,并在触发器激活时运行。

知识检查

此知识检查中的问题与下图中显示的工作流有关。 每个问题都会要求你评估其中一个工作流以找到正确的答案。

社交媒体工作流 电子邮件附件处理工作流
Diagram of a social media monitoring workflow. This workflow triggers when a user posts a new tweet that mentions a specific product. The next action sends the text of the tweet through Text Analytics to determine sentiment. If the sentiment score is greater than 0.7, then a row containing the tweet is added to a database. If the tweet is rated less than 0.7, an email will be sent to customer support. Diagram of an email attachment processing workflow. This workflow is triggered when a new email arrives. Next, a control action uses an *if* statement to check whether the email has an attachment. If the email doesn't have attachments, the workflow ends. If attachments exist, the workflow creates a blob for the email body. Next, another control action called a *for each* loop creates a blob for every attachment. Finally, an email is sent for review.
1.

查看社交媒体工作流的插图以回答此问题。 如果推文的情绪分数正好为 0.7,那么工作流的结果会是什么?

2.

查看电子邮件附件处理工作的插图以回答此问题。 有 6 个附件的电子邮件会创建多少 个 blob?