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 Azure 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 that 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 that your batch receiver and batch sender logic app workflows use 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

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, Visual Studio, or Visual Studio Code, create a logic app with the following name: BatchX12Messages

  2. Link your logic app to your integration account.

  3. In workflow designer, add the Batch trigger, which starts your logic app workflow.

  4. Follow these general steps to add a Batch trigger named Batch messages.

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

  6. Now add an action that encodes each batch:

    1. Follow these general steps to add an X12 action named: Batch encode <any-version>

    2. 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 select Create.

      Create connection between batch encoder and integration account

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

  7. Save your logic app workflow.

  8. If you're using Visual Studio, make sure that 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 workflow

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. Follow these general steps to add the HTTP action named HTTP.

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

  3. Save your workflow.

    Your batch receiver logic app looks like the following 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 that you already created your batch receiver. That way, 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 that your batch receiver and batch sender logic app workflows use 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.

  1. Create another logic app with the following name: SendX12MessagesToBatch

  2. Follow these general steps to add the Request trigger named When a HTTP request is received.

  3. To add an action for sending messages to a batch, follow these general steps to add a Send messages to batch action named Choose a Logic Apps workflow with batch trigger.

    1. Select the BatchX12Messages logic app that you previously created.

    2. Select the BatchX12Messages action named Batch_messages - <your-batch-receiver>.

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

    Your batch sender logic app looks like this example:

    Save your batch sender logic app

Test your workflows

To test your batching solution, post X12 messages to your batch sender logic app workflow using your HTTP request tool and its instructions. 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