title | description | keywords | author | manager | editor | services | documentationcenter | ms.assetid | ms.service | ms.workload | ms.tgt_pltfrm | ms.devlang | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Batch process messages as a group or collection - Azure Logic Apps | Microsoft Docs |
Send and receive messages for batch processing in logic apps |
batch, batch process |
jonfancey |
anneta |
logic-apps |
logic-apps |
na |
na |
na |
article |
08/7/2017 |
LADocs; estfan; jonfan |
To process messages together in groups, you can send data items, or messages, to a batch, and then process those items as a batch. This approach is useful when you want to make sure data items are grouped in a specific way and are processed together.
You can create logic apps that receive items as a batch by using the Batch trigger. You can then create logic apps that send items to a batch by using the Batch action.
This topic shows how you can build a batching solution by performing these tasks:
-
Create a logic app that receives and collects items as a batch. This "batch receiver" logic app specifies the batch name and release criteria to meet before the receiver logic app releases and processes items.
-
Create a logic app that sends items to a batch. This "batch sender" logic app specifies where to send items, which must be an existing batch receiver logic app. You can also specify a unique key, like a customer number, to "partition", or divide, the target batch into subsets based on that key. That way, all items with that key are collected and processed together.
To follow this example, you need these items:
-
An Azure subscription. If you don't have a subscription, you can start with a free Azure account. Otherwise, you can sign up for a Pay-As-You-Go subscription.
-
Basic knowledge about how to create logic apps
-
An email account with any email provider supported by Azure Logic Apps
Before you can send messages to a batch, you must first create a "batch receiver" logic app with the Batch trigger. That way, you can select this receiver logic app when you create the sender logic app. For the receiver, you specify the batch name, release criteria, and other settings.
Sender logic apps need know where to send items, while receiver logic apps don't need to know anything about the senders.
-
In the Azure portal, create a logic app with this name: "BatchReceiver"
-
In Logic Apps Designer, add the Batch trigger, which starts your logic app workflow. In the search box, enter "batch" as your filter. Select this trigger: Batch – Batch messages
-
Provide a name for the batch, and specify criteria for releasing the batch, for example:
-
Batch Name: The name used to identify the batch, which is "TestBatch" in this example.
-
Release Criteria: The batch release criteria, which can be based on the message count, schedule, or both.
-
Message Count: The number of messages to hold as a batch before releasing for processing, which is "5" in this example.
-
Schedule: The batch release schedule for processing, which is "every 5 minutes" in this example.
-
-
Add another action that sends an email when the batch trigger fires. Each time the batch has five items or its past 5 minutes, the logic app sends an email.
-
Under the batch trigger, choose + New step > Add an action.
-
In the search box, enter "email" as your filter. Based on your email provider, select an email connector.
For example, if you have a work or school account, select the Office 365 Outlook connector. If you have a Gmail account, select the Gmail connector.
-
Select this action for your connector: {email provider} - Send an email
For example:
-
-
If you didn't previously create a connection for your email provider, provide your email credentials for authentication when prompted. Learn more about authenticating your email credentials.
-
Set the properties for the action you just added.
-
In the To box, enter the recipient's email address. For testing purposes, you can use your own email address.
-
In the Subject box, when the Dynamic content list appears, select the Partition Name field.
In a later section, you can specify a unique partition key that divides the target batch into logical sets to where you can send messages. Each set has a unique number that's generated by the sender logic app. This capability lets you use a single batch with multiple subsets and define each subset with the name that you provide.
-
In the Body box, when the Dynamic content list appears, select the Message Id field.
Because the input for the send email action is an array, the designer automatically adds a For each loop around the Send an email action. This loop performs the inner action on each item in the batch. So, with the batch trigger set to five items, you get five emails each time the trigger fires.
-
-
Now that you created a batch receiver logic app, save your logic app.
[!IMPORTANT] A partition has a limit of 5,000 messages or 80 MB. If either condition is met, the batch might be released, even when the user-defined condition is not met.
Now create one or more logic apps that send items to the batch defined by the receiver logic app. For the sender, you specify the 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 items with that key.
Sender logic apps need know where to send items, while receiver logic apps don't need to know anything about the senders.
-
Create another logic app with this name: "BatchSender"
-
Add a new step for sending messages to a batch.
-
Under the recurrence trigger, choose + New Step > Add an action.
-
In the search box, enter "batch" as your filter.
-
Select this action: Send messages to batch – Choose a Logic Apps workflow with batch trigger
-
Now select your "BatchReceiver" logic app that you previously created, which now appears as an action.
[!NOTE] The list also shows any other logic apps that have batch triggers.
-
-
Set the batch properties.
-
Batch Name: The batch name defined by the receiver logic app, which is "TestBatch" in this example and is validated at runtime.
[!IMPORTANT] Make sure that you don't change the batch name, which must match the batch name that's specified by the receiver logic app. Changing the batch name causes the sender logic app to fail.
-
Message Content: The message content that you want to send. For this example, add this expression that inserts the current date and time into the message content that you send to the batch:
-
-
Now set up a partition for the batch. In the "BatchReceiver" action, choose Show advanced options.
-
Partition Name: An optional unique partition key to use for dividing the target batch. For this example, add an expression that generates a random number between one and five.
-
Message Id: An optional message identifier and is a generated GUID when empty. For this example, leave this box blank.
-
-
Save your logic app. Your sender logic app now looks similar to this example:
To test your batching solution, leave your logic apps running for a few minutes. Soon, you start getting emails in groups of five, all with the same partition key.
Your BatchSender logic app runs every minute, generates a random number between one and five, and uses this generated number as the partition key for the target batch where messages are sent. Each time the batch has five items with the same partition key, your BatchReceiver logic app fires and sends mail for each message.
Important
When you're done testing, make sure that you disable the BatchSender logic app to stop sending messages and avoid overloading your inbox.