Exchange EDI messages as batches or groups between trading partners in Azure Logic Apps

Applies to: Azure Logic Apps (Consumption)

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. 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.

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. 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.

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. 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 workflow, which sends the messages to the previously created batch receiver.

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:

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.

For this batch receiver, you specify the batch mode, name, release criteria, X12 agreement, and other settings.

  1. 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

    Add Batch trigger

  4. Set the batch receiver properties:

    Property Value Notes
    Batch Mode Inline
    Batch Name TestBatch Available only with Inline batch mode
    Release Criteria Message count based, Schedule based Available only with Inline batch mode
    Message Count 10 Available only with Message count based release criteria
    Interval 10 Available only with Schedule based release criteria
    Frequency minute Available only with Schedule based release criteria

    Provide batch trigger details

    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. In the search box, enter "X12 batch" as your filter, and select this action (any version): Batch encode <version> - X12

      Select X12 Batch Encode action

    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.

      Create connection between batch encoder and integration account

    4. Set these properties for your batch encoder action:

      Property Description
      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.

      BatchName Click inside this box, and after the dynamic content list appears, select the Batch Name token.
      PartitionName 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.

      Batch Encode action details

      For the Items box:

      Batch Encode action items

  6. Save your logic app.

  7. If 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

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. Under the X12 encode action, choose New step.

  2. In the search box, enter "http" as your filter. Select this action: HTTP - HTTP

    Select HTTP action

  3. Set the properties for the HTTP action:

    Property Description
    Method From this list, select POST.
    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.

    Provide HTTP action details

  4. Save your logic app.

    Your batch receiver logic app looks like this example:

    Save your batch receiver logic app

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.

  • 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. Create another logic app with this name: "SendX12MessagesToBatch"

  2. In the search box, enter "when a http request" as your filter. Select this trigger: When a HTTP request is received

    Add the Request trigger

  3. Add an action for sending messages to a batch.

    1. 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

      Select "Choose a Logic Apps workflow with batch trigger"

    3. Now select your "BatchX12Messages" logic app that you previously created.

      Select "batch receiver" logic app

    4. Select this action: Batch_messages - <your-batch-receiver>

      Select "Batch_messages" action

  4. Set the batch sender's properties.

    Property Description
    Batch Name 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

    Set batch properties

  5. Save your logic app.

    Your batch sender logic app looks like this example:

    Save your batch sender logic app

Test your logic apps

To test your batching solution, post X12 messages to your batch sender logic app from Postman or a similar tool. 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