Using Built-In Batch Operations in Azure Logic Apps (Standard)

This post has been republished via RSS; it originally appeared at: Microsoft Tech Community - Latest Blogs - .

Blog Post Contributors: Rama Krishna Rayudu (Principal Software Engineering Manager) and Kent Weare (Principal Product Manager)

 

Batching support is a capability found in Azure Logic Apps (Consumption) that allows developers to send and process messages together in a specific way as groups. This solution collects messages into a batch and waits until your specified criteria is met before releasing and processing the batched messages. Batching can reduce how often your logic app processes messages and help you manage the message flow within your interfaces. For additional information regarding how the Batch feature works, please refer to our documentation.

 

Recently, we had customer inquires about using the batch feature in Azure Logic Apps (Standard) as a built-in connector. Since built-in connectors run within your instance of Azure Logic Apps (Standard), they provide additional performance benefits and are not metered like Azure (managed) connectors.

 

As of this writing, the batch feature can be enabled in the Code view of Azure Logic Apps (Standard). In the future, we will add support in the workflow designer, but using the Code view will unblock customers who require this functionality now.

 

You can create a batch scenario by following these steps. You will need 2 workflows to be created within your Logic App (Standard) instance. One will be a receiver and the other will be a publisher.

 

Start with the receiver workflow by creating a new stateful workflow and copying the following workflow definition into a new workflow’s Code view. Stateless workflows are not currently supported. In addition, when configuring the batch mode, ensure you are using Inline as specified in the code sample. Currently, we only support Inline with Azure Logic Apps (Standard) and don't offer Integration Account support at this time.

 

 

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@triggerBody()",
                "runAfter": {},
                "type": "Compose"
            },
            "HTTP": {
                "inputs": {
                    "body": "@outputs('Compose')",
                    "method": "POST",
                    "uri": "https://requestbin.io/1n79iya1"
                },
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "Http"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "triggers": {
            "Batch_messages": {
                "inputs": {
                    "configurations": {
                        "testbatch": {
                            "releaseCriteria": {
                                "messageCount": 10,
                                "recurrence": {
                                    "frequency": "Minute",
                                    "interval": 5
                                }
                            }
                        }
                    },
                    "mode": "Inline"
                },
                "type": "Batch"
            }
        }
    },
    "kind": "Stateful"
}

 

 

The result should look like the following image. There are a couple important things to consider:

  • Make a note of your workflow’s name. You will need this value in your publisher workflow.
  • Within your trigger, make a note of the name of the value under configurations. In the example below, the name is testbatch. This value can be changed, but we will also need to provide this value in our publisher’s workflow.

Logic App Receiver (Code View)Logic App Receiver (Code View)

Once you save your workflow configuration, you can click on the Designer where you can visually modify your workflow including the Batch trigger’s configuration and any other details.

 

Logic App Receiver (Designer View)Logic App Receiver (Designer View)

 

We are now ready to create our second stateful workflow. Once it has been created, can copy and paste the following code into the Code view.

 

 

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "batch-send": {
                "inputs": {
                    "batchName": "testbatch",
                    "content": "@triggerBody()",
                    "host": {
                        "triggerName": "Batch_messages",
                        "workflow": {
                            "id": "Batch-Receiver"
                        }
                    }
                },
                "runAfter": {},
                "type": "SendToBatch"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "triggers": {
            "When_messages_are_available_in_a_queue": {
                "inputs": {
                    "parameters": {
                        "isSessionsEnabled": false,
                        "queueName": "batchqueuestandard"
                    },
                    "serviceProviderConfiguration": {
                        "connectionName": "serviceBus",
                        "operationId": "receiveQueueMessages",
                        "serviceProviderId": "/serviceProviders/serviceBus"
                    }
                },
                "type": "ServiceProvider"
            }
        }
    },
    "kind": "Stateful"
}

 

 

As mentioned above, pay particular attention to the batchName and the workflow id to ensure the values in your workflow code match that of the receiver.

 

Logic App Publisher (Code View)Logic App Publisher (Code View)

With your workflow code saved, you can now switch over to the Designer where you can make modifications to your workflow. If you decide to continue to use the Service Bus queue trigger, you will need to update your queue configuration and create a connection.

 

Logic App Publisher (Designer View)Logic App Publisher (Designer View)

 

You are now ready to test your workflows. If you would like to see a demo of this in action, please check out the following YouTube video:

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.