In this article I would like to explain Debatching technique in Logic app with two examples. Debatching is a technique of splitting your messages based on any repeated element in the message and process them separately.
here is the detailed description for the above Logic App. In this logic app,
1. Logic App get array of Customer Records like below from SQL
Using foreach loop we process one record at a time in this Logic App. This works alright but since there is no ordering we need to maintain, we could process them parallel. So we choose second option.
Using this Logic App, every 3 mins. we poll a Stored Procedure named as "GetCustomers" and it returns list of customers. This Logic App posts the resultset of "GetCustomers" in to another Logic App. The other Logic App looks like below,
Once we get the ResultSet, we check against empty validation, then we check if the Customer is already present in Salesforce, if not we create one, and send email confirmation.
To debatch the message, we need to use splitOn like below,
it is a code view of our Second Logic App, I have opened it in Chrome:\\apps->Json editor.
My first Logic App, which receives these records and post the same into Second Logic App.
2 instances of Second Logic App has been created.
Each instances of second Logic App would be as follows,
Using debatching technique in Logic App, we could increase the number of instance of Logic App to gain more CPU process to improve the flow. Also, if there are any failures after receiving the records from SQL, we could only retry each record of Second Logic App instances separately. By default, while processing Salesforce records, splitOn("splitOn": "@triggerBody()?.value") is enabled. If you would like to maintain any ordering that you receive it from Salesforce just remove the SplitOn column from your Logic App flow.
{
"$schema"
:
"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"
,
"contentVersion"
"1.0.0.0"
"parameters"
: {
"workflows_LogicAppToSalesforce_name"
"defaultValue"
null
"type"
"String"
},
"workflows_OnPremSQLToSalesforce_name"
"workflows_LogicAppToSalesforce_connectionId"
"workflows_LogicAppToSalesforce_connectionId_1"
"workflows_OnPremSQLToSalesforce_connectionId"
"workflows_OnPremSQLToSalesforce_connectionId_1"
"workflows_OnPremSQLToSalesforce_connectionId_2"
}
"variables"
: {},
"resources"
: [
"Microsoft.Logic/workflows"
"name"
"[parameters('workflows_LogicAppToSalesforce_name')]"
"apiVersion"
"2016-06-01"
"location"
"northcentralus"
"properties"
"state"
"Enabled"
"definition"
"https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#"
"$connections"
"Object"
"triggers"
"manual"
"splitOn"
"@triggerBody()?['Table1']"
"Request"
"kind"
"Http"
"inputs"
"schema"
: {}
"actions"
"Condition"
"ChkCustomerIsPresentinSalesforce"
"CreateCustomerInSF"
"runAfter"
"ApiConnection"
"body"
"item"
"BillingCity"
"@triggerBody()['BillingCity']"
"BillingPostalCode"
"@triggerBody()['BillingPostalCode']"
"BillingState"
"@triggerBody()['BillingState']"
"BillingStreet"
"@triggerBody()['BillingStreet']"
"Name"
"@triggerBody()['CustomerName']"
]
"host"
"api"
"runtimeUrl"
"https://logic-apis-northcentralus.azure-apim.net/apim/salesforce"
"connection"
"@parameters('$connections')['salesforce']['connectionId']"
"method"
"post"
"path"
"/datasets/default/tables/@{encodeURIComponent(encodeURIComponent('Account'))}/items"
"Send_an_email"
"Succeeded"
"Body"
"Dear Integration Owner,\n\n@{body('CreateCustomerInSF')['Name']} account has been created. }\n\nThank you, Have a great day...\n"
"Subject"
"Alert: New Customer has been created successfully."
"To"
"baraneedharan.manoharan@mindtree.com"
"https://logic-apis-northcentralus.azure-apim.net/apim/office365"
"@parameters('$connections')['office365']['connectionId']"
"/Mail"
"GetCusFromSalesforce"
"expression"
"@equals(empty(body('GetCusFromSalesforce')?['value']), true)"
"If"
"get"
"queries"
"$filter"
"Name eq '@{triggerBody()?['CustomerName']}'"
"@not(equals(empty(triggerBody()), true))"
"outputs"
"value"
"office365"
"connectionId"
"[parameters('workflows_LogicAppToSalesforce_connectionId')]"
"connectionName"
"office365-1"
"id"
"/subscriptions/{SubcriptionID}/providers/Microsoft.Web/locations/northcentralus/managedApis/office365"
"salesforce"
"[parameters('workflows_LogicAppToSalesforce_connectionId_1')]"
"/subscriptions/{SubcriptionID}/providers/Microsoft.Web/locations/northcentralus/managedApis/salesforce"
"dependsOn"
: []
"[parameters('workflows_OnPremSQLToSalesforce_name')]"
"Recurrence"
"recurrence"
"frequency"
"Hour"
"interval"
: 3
"Exec_OnPrem_StoreProcedure"
"https://logic-apis-northcentralus.azure-apim.net/apim/sql"
"@parameters('$connections')['sql']['connectionId']"
"/datasets/default/procedures/@{encodeURIComponent(encodeURIComponent('[dbo].[GetCustomers]'))}"
"retryPolicy"
"count"
: 4,
"PT10M"
"fixed"
"HTTP"
"@body('Exec_OnPrem_StoreProcedure')?['ResultSets']"
"headers"
"Content-Type"
"application/json"
"POST"
"uri"
"https://prod-20.northcentralus.logic.azure.com:443/workflows/55b6a9af0e88481eb717cf7aa79c4fe0/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=EMyXO-0vixgTw0Es0SGMb-3FcJNtU7OYIbuH58KKlMs"
"[parameters('workflows_OnPremSQLToSalesforce_connectionId')]"
"[parameters('workflows_OnPremSQLToSalesforce_connectionId_1')]"
"sql"
"[parameters('workflows_OnPremSQLToSalesforce_connectionId_2')]"
"/subscriptions/{SubcriptionID}/providers/Microsoft.Web/locations/northcentralus/managedApis/sql"
Nice article!
Baran Mano edited Revision 17. Comment: Added Code, reference