Send EDI messages in batches to trading partners with Azure Logic Apps
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, 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.
To follow this example, you need these items:
Basic knowledge about how to create logic apps
An existing integration account that's associated with your Azure subscription and is linked to your logic apps
At least two existing partners in your integration account. Each partner must use the X12 (Standard Carrier Alpha Code) qualifier as a business identity in the partner's properties.
An existing X12 agreement in your integration account
To use Visual Studio rather than the Azure portal, make sure you set up Visual Studio for working with Logic Apps.
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.
In the Azure portal or Visual Studio, create a logic app with this name: "BatchX12Messages"
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
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
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.
Now add an action that encodes each batch:
Under the batch trigger, choose New step.
In the search box, enter "X12 batch" as your filter, and select this action (any version): Batch encode <version> - X12
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.
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.
For the Items box:
Save your logic app.
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.
Under the X12 encode action, choose New step.
In the search box, enter "http" as your filter. Select this action: HTTP - HTTP
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.
Save your logic app.
Your batch receiver logic app looks like this example:
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.
Create another logic app with this name: "SendX12MessagesToBatch"
In the search box, enter "when a http request" as your filter. Select this trigger: When a HTTP request is received
Add an action for sending messages to a batch.
Under the HTTP request action, choose New step.
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
Now select your "BatchX12Messages" logic app that you previously created.
Select this action: Batch_messages - <your-batch-receiver>
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
Save your logic app.
Your batch sender logic app looks like this example:
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.