Skip to main content

Az-204 Logic Apps




















Four core components of logic apps. First off, there are triggers. Triggers are the first step in a logic app that are used to start your logic app process. Inside your logic app you have one or more actions. Actions are the shapes that actually do things inside your logic app. You have connectors. Connectors are first-class citizens in Azure. Connectors are shared across logic apps, flow, and Power BI. Connectors are responsible for all your communication with third parties. Connectors are also Microsoft managed so you don't have to worry about maintaining these connectors, and last is flow control. Inside your logic apps you have several options for flow control. This includes do until, foreach, and even simple decision actions.



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.




Calling Existing Logic Apps


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

Popular posts from this blog

App Role assignment to service principal --

 Using Ms Graph Rest API's Permissions One of the following permissions is required to call this API. To learn more, including how to choose permissions, see  Permissions . Permission type Permissions (from least to most privileged) Delegated (work or school account) AppRoleAssignment.ReadWrite.All and Application.Read.All, AppRoleAssignment.ReadWrite.All and Directory.Read.All, Application.ReadWrite.All, Directory.ReadWrite.All Delegated (personal Microsoft account) Not supported. Application AppRoleAssignment.ReadWrite.All and Application.Read.All, AppRoleAssignment.ReadWrite.All and Directory.Read.All, Application.ReadWrite.All, Directory.ReadWrite.All Create 2 app registrations. App role owner will contain the app role that will be assigned to a service principal. The  reader role in approleowner will be added to the approlesubscriber Setup postman to use the Oauth auth flow to get a token for MS Graph. ClientId:   Application (client) ID for approlesubscrib...

ASp.net core 3.1 identity

It is just an extension to cookie authentication. We get a UI, Tables, helper classes, two factor authentication etc. Even EF and its database constructs. So instead of writing code for all of this we can just use these in built features. Extending Default Identity Classes Add a class that inherits from    public class AppUser : IdentityUser     {         public string Behavior { get; set; }     } Also change the user type in login partial.cs under shared folder Then add migrations and update db using migrations. We can customize further.  services.AddDefaultIdentity<AppUser>(options =>              {                 options.SignIn.RequireConfirmedAccount = true;                 options.Password.RequireDigit = false;           ...

Get user groups

 string[] scopes = new string[] { "https://graph.microsoft.com/.default" };             string clientId = "";             string tenantId = "";             string secret = "";                        var options = new TokenCredentialOptions             {                 AuthorityHost = AzureAuthorityHosts.AzurePublicCloud             };             // https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential             try             {                 var clientSecretCredential = new ClientSecretCredential(                        ...