创建或联接 Azure 逻辑应用中的工作流的并行分支Create or join parallel branches for workflow actions in Azure Logic Apps

默认情况下,逻辑应用工作流中的操作按顺序运行。By default, your actions in logic app workflows run sequentially. 若要同时执行独立操作,可以创建并行分支,然后在流中联接这些分支To perform independent actions at the same time, you can create parallel branches, and then join those branches later in your flow.

Tip

如果你有接收数组的触发器并且希望针对每个数组项运行工作流,则可以使用 SplitOn 触发器属性“分离”该数组。If you have a trigger that receives an array and want to run a workflow for each array item, you can debatch that array with the SplitOn trigger property.

先决条件Prerequisites

添加并行分支Add parallel branch

若要同时运行独立的步骤,可以在现有步骤旁边添加平行分支。To run independent steps at the same time, you can add parallel branches next to an existing step.

并行运行步骤

逻辑应用等待所有分支都完成后才继续执行工作流。Your logic app waits for all branches to finish before continuing workflow. 仅当并行分支的 runAfter 属性值匹配已完成父步骤的状态时,才运行并行分支。Parallel branches run only when their runAfter property values match the finished parent step's status. 例如,branchAction1branchAction2 都设置为仅在 parentActionSucceeded 状态完成时才运行。For example, both branchAction1 and branchAction2 are set to run only when the parentAction completes with Succeeded status.

Note

在开始之前,逻辑应用必须已有可添加平行分支的步骤。Before you start, your logic app must already have a step where you can add parallel branches.

  1. Azure 门户的逻辑应用设计器中打开逻辑应用。In the Azure portal, open your logic app in Logic App Designer.

  2. 将指针悬停在要添加平行分支的步骤上方的箭头上。Move your pointer over the arrow above the step where you want to add parallel branches. 选择出现的加号 (+),然后选择“添加并行分支”。Choose the plus sign (+) that appears, and then choose Add a parallel branch.

    添加并行分支

  3. 在搜索框中,查找并选择所需的操作。In the search box, find and select the action you want.

    查找并选择所需的操作

    现在,所选操作将在并行分支中显示,例如:Your selected action now appears in the parallel branch, for example:

    查找并选择所需的操作

  4. 现在,在每个并行分支中添加所需的步骤。Now, in each parallel branch, add the steps you want. 若要将其他操作添加到分支,请将指针移动到要添加顺序操作的操作下。To add another action to a branch, move your pointer under the action where you want to add a sequential action. 选择出现的加号 (+),然后选择“添加操作”。Choose the plus (+) sign that appears, and then select Add an action.

    将顺序操作添加到并行分支

  5. 在搜索框中,查找并选择所需的操作。In the search box, find and select the action you want.

    查找并选择顺序操作

    现在,所选操作将在当前分支中显示,例如:Your selected action now appears within the current branch, for example:

    查找并选择顺序操作

若要将分支重新合并在一起,请联接平行分支To merge branches back together, join your parallel branches.

并行分支定义 (JSON)Parallel branch definition (JSON)

如果正在代码视图中操作,可以改为在逻辑应用的 JSON 定义中定义并行结构,例如:If you're working in code view, you can define the parallel structure in your logic app's JSON definition instead, for example:

{
  "triggers": {
    "myTrigger": { }
  },
  "actions": {
    "parentAction": {
      "type": "<action-type>",
      "inputs": { },
      "runAfter": {}
    },
    "branchAction1": {
      "type": "<action-type>",
      "inputs": { },
      "runAfter": {
        "parentAction": [
          "Succeeded"
        ]
      }
    },
    "branchAction2": {
      "type": "<action-type>",
      "inputs": { },
      "runAfter": {
        "parentAction": [
          "Succeeded"
        ]
      }
    }
  },
  "outputs": {}
}

联接并行分支Join parallel branches

若要将并行分支合并在一起,只需在所有分支的底部添加一个步骤。To merge parallel branches together, just add a step at the bottom under all the branches. 此步骤在所有平行分支完成运行后运行。This step runs after all the parallel branches finish running.

联接并行分支

  1. Azure 门户中的逻辑应用设计器中查找并打开逻辑应用。In the Azure portal, find and open your logic app in Logic App Designer.

  2. 在想要联接的平行分支下,选择 新建步骤Under the parallel branches you want to join, choose New step.

    添加要联接的步骤

  3. 在搜索框中,查找并选择操作,作为联接分支的步骤。In the search box, find and select the action you want as the step that joins the branches.

    查找并选择联接平行分支的操作

    现在已合并并行分支。Your parallel branches are now merged.

    已联接的分支

联接定义 (JSON)Join definition (JSON)

如果正在代码视图中操作,可以改为在逻辑应用的 JSON 定义中定义联接结构,例如:If you're working in code view, you can define the join structure in your logic app's JSON definition instead, for example:

{
  "triggers": {
    "myTrigger": { }
  },
  "actions": {
    "parentAction": {
      "type": "<action-type>",
      "inputs": { },
      "runAfter": {}
    },
    "branchAction1": {
      "type": "<action-type>",
      "inputs": { },
      "runAfter": {
        "parentAction": [
          "Succeeded"
        ]
      }
    },
    "branchAction2": {
      "type": "<action-type>",
      "inputs": { },
      "runAfter": {
        "parentAction": [
          "Succeeded"
        ]
      }
    },
    "joinAction": {
      "type": "<action-type>",
      "inputs": { },
      "runAfter": {
        "branchAction1": [
          "Succeeded"
        ],
        "branchAction2": [
          "Succeeded"
        ]
      }
    }
  },
  "outputs": {}
}

获取支持Get support

后续步骤Next steps