Debatching and Batching play a primary role in integration. In BizTalk we used to do it in Envelope, Schema, Pipeline etc. We also have different ways to do them In Logic Apps. I will try to cover a few below.
Debatching:Below are different ways we can do debatching in Logic Apps.
- Split On (Parallel)
- For-Each (Sequential)
Let’s consider a Scenario where you are receiving a Sample Json which consists of Orders in the below structure.
We need to Debatch it and send it to a Storage Queue.
I have prepared the Logic App Like below.
Logic App is fairly simple, the only configuration which we need to do is add the Split On. Go into HTTP Request Settings and you will find the Split On property as shown below:
Switch the property to ON and define the Array. In my case I am using Triggered Json.
Now if we Trigger the Logic App with the above example, you will see that 3 Instances got Triggered in parallel and sent to Storage Queue as shown below:
In this way, Split On can help you to Debatch and Trigger the messages in parallel.
For Each:Another approach is to use For Each and to move the messages sequentially. It’s more like a Singleton pattern, so only one instance of Logic app will do the job. We modify the Logic App to use For Each as shown below:
Now if we Trigger the Logic App you will see that only one instance of Logic App is triggered and looking inside the Details you will see that For Each has been fired multiple times.
For this example we will use the Batching Connector of Logic Apps.
Let’s take the above example where we have Debatched the Orders. Now we will re-assemble those Orders.
First step is to create a Batching Logic App. It looks like below:
- I have set the Batch Mode to Inline and we can use Integration Account to control the configurations externally.
- I have set the Release Criteria to Message Count Based, so when the Message Count in the batch reaches 3 it will release the Message. So, in other words every Batch will have 3 Messages.
Second Step is to create the Batch Sender Logic App. It looks Like below
The Batch Sender Logic App is set up as follows:
- It has the Storage queue Trigger which will take the Messages.
- Then it has the Bathing Connector which has the Batch Name, Batch Name has to be the same which we have given earlier
- This Logic App will send the Messages to Batching.
If we test the solution, we will get an email Like below:
We see that the content is the actual Message we have sent to Storage Queue and we can filter it in the Logic App as well. You can also see that there are 3 Messages in each Batch.
These are some of the ways we can do Batching and Debatching in Logic Apps.
Topics from this blog: Blog