在 Azure 逻辑应用中的贸易合作伙伴之间以批或组的形式交换 EDI 消息Exchange EDI messages as batches or groups between trading partners in Azure Logic Apps

在企业到企业 (B2B) 方案中,合作伙伴通常以组或批的形式交换消息。 In business to business (B2B) scenarios, partners often exchange messages in groups or batches. 使用逻辑应用生成批处理解决方案时,可将消息发送到参与方,然后以批的形式统一处理这些消息。When you build a batching solution with Logic Apps, you can send messages to trading partners and process those messages together in batches. 本文以 X12 为例,介绍如何通过创建“批发送方”逻辑应用和“批接收方”逻辑应用来批处理 EDI 消息。This article shows how you can batch process EDI messages, using X12 as an example, by creating a "batch sender" logic app and a "batch receiver" logic app.

批处理 X12 消息的方式如同处理其他消息:使用批处理触发器将消息收集到某个批中,然后使用批处理操作将消息发送到批。Batching X12 messages works like batching other messages; you use a batch trigger that collects messages into a batch and a batch action that sends messages to the batch. 此外,在消息转到参与方或其他目标之前,X12 批处理包含一个 X12 编码步骤。Also, X12 batching includes an X12 encoding step before the messages go to the trading partner or other destination. 有关批处理触发器和操作的详细信息,请参阅批处理消息To learn more about the batch trigger and action, see Batch process messages.

在本文中,我们将通过遵循以下特定顺序在同一个 Azure 订阅和 Azure 区域中创建两个逻辑应用,来生成批处理解决方案:In this article, you'll build a batching solution by creating two logic apps within the same Azure subscription, Azure region, and following this specific order:

  • “批接收方”逻辑应用:接受消息并将其收集到批中,直到满足发布和处理这些消息的指定条件。A "batch receiver" logic app, which accepts and collects messages into a batch until your specified criteria is met for releasing and processing those messages. 在此方案中,批接收方还会使用指定的 X12 协议或合作伙伴标识来编码批中的消息。In this scenario, the batch receiver also encodes the messages in the batch by using the specified X12 agreement or partner identities.

    请务必先创建批接收方,然后才能在创建批发送方时选择批处理目标。Make sure you first create the batch receiver so you can later select the batch destination when you create the batch sender.

  • “批发送方”逻辑应用:将消息发送到前面创建的批接收方。A "batch sender" logic app, which sends the messages to the previously created batch receiver.

请确保批接收方和批发送方共享同一个 Azure 订阅和 Azure 区域。 Make sure your batch receiver and batch sender share the same Azure subscription and Azure region. 否则,在创建批发送方时无法选择批接收方,因为它们相互不可见。If they don't, you can't select the batch receiver when you create the batch sender because they're not visible to each other.

必备条件Prerequisites

若要按照此示例进行操作,需要以下这些项:To follow this example, you need these items:

创建 X12 批接收方Create X12 batch receiver

在将消息发送到某个批之前,该批必须存在且充当这些消息要发送到的目标。Before you can send messages to a batch, that batch must first exist as the destination where you send those messages. 因此,首先必须创建可以通过“批处理”触发器启动的“批接收方”逻辑应用。 So first, you must create the "batch receiver" logic app, which starts with the Batch trigger. 这样,在创建“批发送方”逻辑应用时,便可以选择批接收方逻辑应用。That way, when you create the "batch sender" logic app, you can select the batch receiver logic app. 批接收方会持续收集消息,直到满足发布和处理这些消息的指定条件。The batch receiver continues collecting messages until your specified criteria is met for releasing and processing those messages. 尽管批接收方不需要知道有关批发送方的任何信息,但批发送方必须知道要将消息发送到的目标。While batch receivers don't need to know anything about batch senders, batch senders must know the destination where they send the messages.

对于此批接收方,需指定批模式、名称、发布条件、X12 协议和其他设置。For this batch receiver, you specify the batch mode, name, release criteria, X12 agreement, and other settings.

  1. Azure 门户或 Visual Studio 中,创建名为“BatchX12Messages”的逻辑应用In the Azure portal or Visual Studio, create a logic app with this name: "BatchX12Messages"

  2. 将逻辑应用链接到集成帐户Link your logic app to your integration account.

  3. 在逻辑应用设计器中,添加触发器,这会启动逻辑应用工作流。In Logic Apps Designer, add the Batch trigger, which starts your logic app workflow. 在搜索框中,输入“批”作为筛选器。In the search box, enter "batch" as your filter. 选择此触发器:“批处理消息” Select this trigger: Batch messages

    添加批触发器

  4. 设置批接收方属性:Set the batch receiver properties:

    propertiesProperty Value 说明Notes
    批处理模式Batch Mode 内联Inline
    批名称Batch Name TestBatchTestBatch 仅适用于“内联”批处理模式 Available only with Inline batch mode
    发布条件Release Criteria 基于消息计数、基于计划Message count based, Schedule based 仅适用于“内联”批处理模式 Available only with Inline batch mode
    消息计数Message Count 1010 仅适用于“基于消息计数”发布条件 Available only with Message count based release criteria
    间隔 Interval 1010 仅适用于“基于计划”发布条件 Available only with Schedule based release criteria
    频率Frequency minuteminute 仅适用于“基于计划”发布条件 Available only with Schedule based release criteria

    提供批处理触发器详细信息

    Note

    本示例不会设置批的分区,因此每个批次使用相同的分区键。This example doesn't set up a partition for the batch, so each batch uses the same partition key. 若要详细了解分区,请参阅批处理消息To learn more about partitions, see Batch process messages.

  5. 现在,添加一个用于编码每个批的操作:Now add an action that encodes each batch:

    1. 在批处理触发器下,选择“新建步骤”。 Under the batch trigger, choose New step.

    2. 在搜索框中,输入“X12 批”作为筛选器,并选择以下操作(任何版本):“批编码 <版本> - X12” In the search box, enter "X12 batch" as your filter, and select this action (any version): Batch encode <version> - X12

      选择“X12 批编码”操作

    3. 如果事先未连接到集成帐户,现在请创建连接。If you didn't previously connect to your integration account, create the connection now. 提供连接的名称,选择集成帐户,然后选择“创建”。 Provide a name for your connection, select the integration account you want, and then choose Create.

      在批编码器与集成帐户之间创建连接

    4. 设置批编码器操作的以下属性:Set these properties for your batch encoder action:

      propertiesProperty 说明Description
      X12 协议的名称Name of X12 agreement 打开列表,并选择现有的协议。Open the list, and select your existing agreement.

      如果该列表为空,请确保将逻辑应用链接到包含所需协议的集成帐户If your list is empty, make sure you link your logic app to the integration account that has the agreement you want.

      BatchNameBatchName 在此框中单击,显示动态内容列表后,选择“批名称”标记。 Click inside this box, and after the dynamic content list appears, select the Batch Name token.
      PartitionNamePartitionName 在此框中单击,显示动态内容列表后,选择“分区名称”标记。 Click inside this box, and after the dynamic content list appears, select the Partition Name token.
      Items 关闭项详细信息,然后在此框中单击。Close the item details box, and then click inside this box. 显示动态内容列表后,选择“已批处理的项”标记。 After the dynamic content list appears, select the Batched Items token.

      “批编码”操作详细信息

      对于“项”框: For the Items box:

      “批编码”操作项

  6. 保存逻辑应用。Save your logic app.

  7. 如果使用 Visual Studio,请确保将批接收方逻辑应用部署到 AzureIf you're using Visual Studio, make sure you deploy your batch receiver logic app to Azure. 否则,在创建批发送方时无法选择批接收方。Otherwise, you can't select the batch receiver when you create the batch sender.

测试逻辑应用Test your logic app

为确保批接收方按预期方式工作,可以添加一个 HTTP 操作用于测试,并将批处理的消息发送到请求 Bin 服务To make sure your batch receiver works as expected, you can add an HTTP action for testing purposes, and send a batched message to the Request Bin service.

  1. 在 X12 编码操作下,选择“新建步骤”。 Under the X12 encode action, choose New step.

  2. 在搜索框中,输入“http”作为筛选器。In the search box, enter "http" as your filter. 选择此操作:“HTTP - HTTP” Select this action: HTTP - HTTP

    选择“HTTP”操作

  3. 为 HTTP 操作设置属性:Set the properties for the HTTP action:

    propertiesProperty 说明Description
    方法Method 在此列表中选择“POST”。 From this list, select POST.
    UriUri 生成请求 bin 的 URI,然后在此框中输入该 URI。Generate a URI for your request bin, and then enter that URI in this box.
    正文Body 在此框中单击,动态内容列表打开后,选择“按协议名称进行批编码”部分显示的“正文”标记。 Click inside this box, and after the dynamic content list opens, select the Body token, which appears in the section, Batch encode by agreement name.

    如果未显示“正文”标记,请在“按协议名称进行批编码”旁边选择“查看更多”。 If you don't see the Body token, next to Batch encode by agreement name, select See more.

    提供 HTTP 操作详细信息

  4. 保存逻辑应用。Save your logic app.

    批接收方逻辑应用如以下示例所示:Your batch receiver logic app looks like this example:

    保存批接收方逻辑应用

创建 X12 批发送方Create X12 batch sender

现在创建一个或逻辑应用,用于将消息发送到批接收方逻辑应用。Now create one or more logic apps that send messages to the batch receiver logic app. 在每个批发送方中,指定批接收方逻辑应用和批名称、消息内容及其他任何设置。In each batch sender, you specify the batch receiver logic app and batch name, message content, and any other settings. 可以选择提供唯一分区键以将批划分为子集,从而收集具有该键的消息。You can optionally provide a unique partition key to divide the batch into subsets to collect messages with that key.

  • 确保已创建批接收方,以便在创建批发送方时,可以选择现有的批接收方作为目标批。Make sure you've already created your batch receiver so when you create your batch sender, you can select the existing batch receiver as the destination batch. 尽管批接收方不需要知道有关批发送方的任何信息,但批发送方必须知道要将消息发送到何处。While batch receivers don't need to know anything about batch senders, batch senders must know where to send messages.

  • 请确保批接收方和批发送方共享同一个 Azure 区域和 Azure 订阅。 Make sure your batch receiver and batch sender share the same Azure region and Azure subscription. 否则,在创建批发送方时无法选择批接收方,因为它们相互不可见。If they don't, you can't select the batch receiver when you create the batch sender because they're not visible to each other.

  1. 创建名为“SendX12MessagesToBatch”的另一个逻辑应用Create another logic app with this name: "SendX12MessagesToBatch"

  2. 在搜索框中,输入“收到 http 请求时”作为筛选器。In the search box, enter "when a http request" as your filter. 选择此触发器:“收到 HTTP 请求时” Select this trigger: When a HTTP request is received

    添加“请求”触发器

  3. 添加用于将消息发送到批的操作。Add an action for sending messages to a batch.

    1. 在 HTTP 请求操作下,选择“新建步骤”。 Under the HTTP request action, choose New step.

    2. 在搜索框中,输入“批”作为筛选器。In the search box, enter "batch" as your filter. 选择“操作”列表,然后选择此操作:“选择具有批处理触发器的逻辑应用工作流 - 将消息发送到批” Select the Actions list, and then select this action: Choose a Logic Apps workflow with batch trigger - Send messages to batch

      选择“选择具有批处理触发器的逻辑应用工作流”

    3. 选择前面创建的“BatchX12Messages”逻辑应用。Now select your "BatchX12Messages" logic app that you previously created.

      选择“批接收方”逻辑应用

    4. 选择此操作:“Batch_messages - <批接收方>”Select this action: Batch_messages - <your-batch-receiver>

      选择“Batch_messages”操作

  4. 设置批发送方的属性。Set the batch sender's properties.

    propertiesProperty 说明Description
    批名称Batch Name 接收方逻辑应用定义的批名称,在本示例中为“TestBatch”The batch name defined by the receiver logic app, which is "TestBatch" in this example

    重要说明:批名称在运行时将接受验证,必须与接收方逻辑应用指定的名称相匹配。Important: The batch name gets validated at runtime and must match the name specified by the receiver logic app. 更改批名称会导致批发送方失败。Changing the batch name causes the batch sender to fail.

    消息内容Message Content 要发送的消息内容,在本示例中为“正文”标记 The content for the message you want to send, which is the Body token in this example

    设置批属性

  5. 保存逻辑应用。Save your logic app.

    批发送方逻辑应用如以下示例所示:Your batch sender logic app looks like this example:

    保存批发送方逻辑应用

测试逻辑应用Test your logic apps

若要测试批处理解决方案,请通过 Postman 或类似工具将 X12 消息发布到批发送方逻辑应用。To test your batching solution, post X12 messages to your batch sender logic app from Postman or a similar tool. 很快,请求 bin 中就会每隔 10 分钟或者以 10 个一批的形式接收 X12 消息,所有这些消息具有相同的分区键。Soon, you start getting X12 messages in your request bin, either every 10 minutes or in batches of 10, all with the same partition key.

后续步骤Next steps