LOGIC APP CREATION
We will create a logic app that will start when an http request is received and based on the request body it will make decisions
Go to Logic Apps Designer and select the type of request to start the logic app. In this case we will start the app when we get an httprequest.
Click on HttpRequest, here we get a new screen where we can specify the payload that we will receive.
Click on use sample schema and paste the request json (sample). Logic apps will generate the schema from it.
The JSON that I have used is as follows.
{
"name":"anish",
"age":32,
"category":"student"
}
Now we can declare variables to hold values. So I will create a variable to hold the minage. We will process data based on this minage value. Click on next and add a variable and choose initialize , since we are using the variable for the first time.
Similarly I have created another variable to hold a boolean variable approved. If minage is greater that the age in the http request body we will set this value to true and return it in the response body.
I have created a variable that will hold the minage . The Logic app will parse the JSON in the request body and we will be able to access those values in all the action or conditions that we add in a logic app.
If we look at the image below I have added a condition that if the age in the request body is greater than the minage variable that we created then we set the approved value to true else we set the approved value to false.
To Debug just go to overview and click on the specific run to get more details.
Switch Statements, Loops etc
Foreach allows for looping over a collection of data to process each record one at a time. To configure the foreach you would select the value that you want to loop over once you add the foreach statement. You can add actions, conditions, or other logic under your foreach statement. One thing to point out is that the foreach statement by default will run 20 concurrent foreach loops in parallel. This is not always the desired behavior so you can adjust that under Settings to override that behavior. A foreach can have up to 50 concurrent loops and it can loop over items with collections as large as 100, 000. Do Until. Do until runs until a specific condition is met, a loop limit is reached, or a specific amount of time has passed. Once you add the do until to your logic app, you can select the value to evaluate on the left.
Just add a loop inside an action and we get the individual item in the array which can be processed.
Concurrency Control
Retry Policy
The default retry policy is four retries over an exponentially increasing scale. You can see the retry policy on every single action by going under Settings. Here under Settings under Retry Policy you have the ability to change it from the default retry policy. One thing to point out is the retry policy will execute if the action gets back a 408, 429 or any 500 error code.
In this example, I have created 4 blob containers.
The idea is to upload files to container1 and based on the type of the file uploaded we will copy the file to the other container. That is , if we upload an image then we copy the image to the image container, if its an mp3 file then we move it to the audiocontainer else we move it to container 2.
This is the logic app we created, the app starts when a blob is uploaded to container1.
I pass the blob name to an azure function that splits the name and returns the extension of the file. This is just an example.
Next we set this value to a variable called typename.
Next is a switch case that has an action that copies the blob to the respective blob based on the extension of the uploaded blob.
Finally we look at the logic app overview to check how the logic app ran.
NESTED Logic Apps
Synchronous is when we start a logic app and then wait for its response. Asynchronous is when we make a request and dont wait for its response.
Goto settings and turn off the Asynchronous radio button.
Retry policies: Default is 4, if we have complex time consuming logic then retrying multiple times is not a good idea.
For Apps that are in the same subscription just use the logic app action as shown above. For apps in different subscription use the http action
DEMO:
We create 2 logic apps, to the primary one we send a collection of data which loops through the collection and sends each item to the secondary logic app that sends each message to a service bus queue.
we create 2 logic apps.
SampleLogicApp will loop and send each data to secondarylogicapp which will push the message to a service bus queue. in the forach action we choose an action for a logic app which will list all the existing logic apps in our subscription
And pass the individual item from the forloop iteration
SecondaryLogicApp
To call the logic app, go to the primary app and use postman to make the call and we can see that 3 messages that we added in the request body have been pushed to the service bus queue.
LARGE DATA
Blob and FTP support data transfer in chunks so it supports up to 1 gb.
High Volume Scenarios
EXCEPTION HANDLING
Creating Custom Connectors
https://www.youtube.com/watch?v=qwI0zaTBSHQ
Create an API and go to azure portal. Select create custom connector and import the API by swagger URL or file or postman collection. Then add security info and other details for the connector and update.
Logics Apps using ARM Templates
https://docs.microsoft.com/en-us/learn/modules/create-deploy-logic-apps-using-arm-templates/
Comments
Post a Comment