Try for free Book a demo

Logic App Best Practices, Tips, and Tricks: #23 Debatching Messages

Microsoft Azure

3 Mins Read

Debatching messages in Logic Apps

Welcome again to another Logic Apps Best Practices, Tips, and Tricks. In my previous blog posts, I talked about some of the essential best practices you should have while working with Azure Logic Apps. Check out these Logic App tips and tricks!

Today I will speak about another important Best practice, Tips, and Tricks that you need to consider while designing your business processes (Logic Apps): How to debatch inbound messages.
Debatching messages in Logic Apps

Debatching messages

In simple words, debatching or splitting is the process of extracting individual messages/records from a file containing multiple records/messages and creating separate files for all those individual messages/records to process them separately.

Debatching messages in Azure Logic Apps

This is a well-known Enterprise Integration Pattern – Splitter. You can read more about this pattern here.

Because it is a well-known Enterprise Integration Pattern, that also means that Debatching plays an important role in several BizTalk Server Integration solutions. We can use several strategies to implement debatching in BizTalk Server, like using an Envelope Schema and a custom Pipeline.

Of course, when we speak about Logic Apps, we should expect to have similar capabilities to apply this integration pattern. And indeed, we have! Not only XML but also JSON messages.

Logic Apps offer a Split On setting that can be enabled to the Logic App trigger. In this Split On option, we need to provide an expression of an array structure. By doing that, the split-on will start an instance of the workflow per item in the selected array.

So, for example, if we define the following JSON schema as the Request body JSON Schema in the trigger of our Logic App:

{
    “properties”: {
        “People”: {
            “items”: {
                “properties”: {
                    “name”: {
                        “type”: “string”
                    }
                },
                “required”: [
                    “name”
                ],
                “type”: “object”
            },
            “type”: “array”
        }
    },
    “type”: “object”
}

Then we can define the trigger settings – click on three dots and select the option Settings – the following expression on the Split On option:

  • @triggerBody()?[‘People’]

Using Spliton

Now, when we submit a message with multiple People inside, several workflows will be started according to the number of items present in the message.

Debatching messages in Logic Apps Azure

Logic Apps are built on APIs, natively supporting JSON messages. So, it is quite easy to implement this pattern, but can it also be done on old-school integration using XML? Currently, XML is still widely spread, so it would be amazing to have also support for this format. And yes, we have it!

And it is quite similar to the JSON format. Take this example:

<PurchaseOrders xmlns=”http://www.demo.com”>
<PO>

</PO>
<PO>

</PO>
</PurchaseOrders>

We need to set the following expression on the Split On Array option:

  • xpath(xml(triggerBody()),’//*[local-name()=”PO” and namespace-uri() =”http://www.demo.com”]’)

I hope you enjoy this developer tip and stay tuned for the following Logic App Best practices, Tips, and Tricks.

Related reading

This article was published on Mar 6, 2023.

Related Articles