Batching(Aggregating) messages in Logic App | Logic apps Batching

{tocify} $title={Table of Contents}

Introduction



In last couple of posts Debatching(Splitting) XML Message in Logic Apps - ForEach and SplitOn  and Debatching(Splitting) JSON Message in Logic Apps - ForEach and SplitOn we understood about Splitter pattern and how to use it to split/debatch messages.

Batching or aggregation is opposite process of debatching/splitting where we group various individual message and send them as a single composed message for further processing.

aggregator pattern

If you have worked on BizTalk, you can relate to the Parallel convoy - Which is used to receive multiple messages and act upon them based on certain condition. 


Likewise , here the Aggregator/Batch Processor gets started as soon as it receives individual message and keeps on waiting and receiving for other individual messages till the time the Release condition is met.

Release conditions are to set boundary to the compose message, like if size of composed message is reached to certain limit or if count of messages grouped reached to limit or batched messages have to be sent at a scheduled time etc.

When done with grouping it is further sent for processing as one Batch this certainly increases throughput, performance, cost etc - as the number of calls to destination system is reduced.

In this post we will see how to batch/aggregate message, for this we would create two logic app 
1. BatchProcessor 
2. BatchProcessCaller


Steps to implement Aggregator/Batching Pattern in Logic App


Create a Batch Processor Logic App

From the Azure Portal select Create a resource -> search of “Logic App” -> click Create button

Create BatchProcessor Logic App

After instance is created, go to logic app designer and to add trigger - search for Batch. Select the Batch message trigger and configure batch process trigger .

  • Batch Mode 
Here we have two option

- Inline: For defining release criteria inside the batch trigger itself (for this post am using this - it's kind of hard coding). 

IMO This should be opted if you don't have integration account or you have limited batch processing requirement.

- Integration Account: Ideally, this is should be preferred, as it helps for defining multiple release criteria configurations and also you don't have to make updates in Logic app every time release criteria is changed . It is like a configuration file sitting in an integration account,so you can maintain these configurations all in one place rather than in separate logic apps
  • Batch Name
The name for your batch, which is "CommonBatch" in this example  and applies only to Inline batch mode
  • Release Criteria

As we have used Inline batch mode, we need to select the criteria to meet before processing each batch (we can select multiple criteria also):
- Message count based: Release the batch based on the number of messages collected by the batch.
- Size based: Release the batch based on the total size in bytes for all messages collected by that batch.
- Schedule: Release the batch based on a recurrence schedule, which specifies an interval and frequency. In the advanced options, you can also select a time zone and provide a start date and time.
- Select all: Use all the specified criteria.

Here Message count is selected with count as 3

configuring batch process trigger in logic app

Now, what you want to do with Batched Message? you can send it to the required destination/do further processing, for the sake of this post, I have used send email action to send the batched message
send email action


Note : Batch trigger is a special trigger meant for collecting messages and it only starts the instance once it's release condition is met - so you won't see it's instance in run history till it reaches it's release point. 

Also you would not be able to call it outside of your subscription or from different region.


Create a caller Logic App


From the Azure Portal select Create a resource -> search of “Logic App” -> click Create button.

In designer select http tigger and in next action search for Batch, you should see all the logic apps which have Batchtrigger, select the one created in above step.


call batch process logic app
As soon as you select it, Trigger Name and Workflow will auto populate, against Batch Name give the same name used in step 1 and for Message content provide triggerbody.

Configure batch process logic app

That's it, ready to use.



Testing



Using Postman, sent 3 request(JSON) having three two properties in it in it to the BatchProcessCaller logic app

request to logic app


And below is the email received - which is sent by BatchProcessor logic app

The message contains some additional fields apart from content(highlighted in yellow), which are details about the Batch .

We saw how we can batch json messages, in following post have covered about XML messages batching  -    XML Batching(Aggregation) in Logic App


If you have questions or suggestions, feel free to do in comments section below !!!


Do share if you find this helpful .......
 
                       Knowledge Sharing is Caring !!!!!!


Learn More about Logic App

    Post a Comment

    If you have any suggestions or questions or want to share something then please drop a comment

    Previous Post Next Post