Batching (aggregating) messages using batch receive and batch sender in a Logic App

Below is a step-by-step guide to create an Azure Logic App workflow that uses Batch Receive and Batch Sender actions to process XML messages. The workflow will:

  1. Receive XML messages.
  2. Add a root tag to the batched XML messages.
  3. Send the final batched XML message via Gmail.

Step-by-Step Workflow

Step 1: Create the Batch Receiver Logic App

This Logic App will receive and process XML messages in batches.

  1. Go to the Azure portal and create a new Logic App.
  2. Add a Batch Trigger:
    • Search for Batch and select When messages are received in a batch.
    • Configure the batch settings:
      • Release criteria: Message count base
      • Message Count: 2
      • Mode: Inline
  3. Add a Initialize variable set type: String and value: “</Employees>”.
  4. Add a For Each loop to iterate through the batch of messages.
  5. Inside the loop, add a Append to string variable action to process each XML message. For example:
    • Value: @item()['content']
  6. Add a Append to string variable action outside the loop to add a end root tag to the batched XML messages. For example:
  7. Value: </Employees>
  8. Add a Gmail action to send the final batched XML message:
    • To: Enter the recipient’s email address.
    • SubjectBatched Final Message
    • Body: Here is the result of the batched message
      @{variables('rootName-Var')}

Step 2: Create the Batch Sender Logic App

This Logic App will send XML messages to the Batch Receiver.

  1. Create another Logic App.
  2. Add a trigger When a HTTP request is received.
  3. Add a Batch Sender action:
    • Search for Batch and select Send messages to batch.
    • Configure the batch settings:
      • Batch Receiver: Select the Logic App created in Step 1.
      • Message Content@triggerBody()

Here's how Logic Apps should look:

Batch Receiver Logic App
estudy247-la-test-batch-15
Batch Sender Logic App
estudy247-la-test-batch-16

Testing the Workflow

  1. The Batch Sender will send the XML messages to the Batch Receiver.
  2. The Batch Receiver will process the messages based on condition (e.g. message count = 2).
  3. The Batch Receiver will add a root tag to the batched XML messages.
  4. The Batch Receiver will send the final batched XML message via Gmail.

Sample Input

Batch Sender sends 2 XML messages:

  <message>
    <id>1</id>
    <name>John Doe</name>
  </message>
  <message>
    <id>2</id>
    <name>Jane Smith</name>
  </message>

Sample Output

The Batch Receiver will process the messages and add a root tag:

<Employees>
  <message>
    <id>1</id>
    <name>John Doe</name>
  </message>
  <message>
    <id>2</id>
    <name>Jane Smith</name>
  </message>
</Employees>

You can download the logic app template from the estudy247 GitHub repository – Batch Receiver: la-test-batch-15 and Batch Sender: la-test-batch-16

Post a comment

Leave a Comment

Scroll to Top