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
An Azure subscription. If you don't have a subscription, you can start with a free Azure account.
Basic knowledge about how to create logic app workflows. For more information, see Create an example Consumption logic app workflow in multitenant Azure 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 Azure Logic Apps.
Install or use a tool that can send HTTP requests to test your solution, for example:
- Visual Studio Code with an extension from Visual Studio Marketplace
- PowerShell Invoke-RestMethod
- Microsoft Edge - Network Console tool
- Bruno
- curl
Caution
For scenarios where you have sensitive data, such as credentials, secrets, access tokens, API keys, and other similar information, make sure to use a tool that protects your data with the necessary security features, works offline or locally, doesn't sync your data to the cloud, and doesn't require that you sign in to an online account. This way, you reduce the risk around exposing sensitive data to the public.
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, Visual Studio, or Visual Studio Code, create a logic app with the following name: BatchX12Messages
In workflow designer, add the Batch trigger, which starts your logic app workflow.
Follow these general steps to add a Batch trigger named 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 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.
Now add an action that encodes each batch:
Follow these general steps to add an X12 action named: Batch encode <any-version>
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.
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 workflow.
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.
Follow these general steps to add the HTTP action named 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 workflow.
Your batch receiver logic app looks like the following 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 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.
Create another logic app with the following name: SendX12MessagesToBatch
Follow these general steps to add the Request trigger named When a HTTP request is received.
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.
Select the BatchX12Messages logic app that you previously created.
Select the BatchX12Messages action named 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 workflow.
Your batch sender logic app looks like this example:
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.