Microsoft Azure |Automate Common Tasks With Azure Logic Apps.

Microsoft Azure |Automate Common Tasks With Azure Logic Apps.

Introduction

Logic Apps are a relatively new feature of Microsoft Azure that makes it simple to build complex workflows using one or more of the over 175 different connectors. Since the Logic Apps are server less, we do not need to worry about server sizing. The platform will scale to meet our demand, and we are only charged for what we use.

Azure Logic Apps are hosted in Microsoft Azure, and so, there’s no infrastructure component, there’s no on-premises or virtual machines to manage. On that basis, and in terms of how we pay for it, it is essentially server-less.

Logic App can be trigger launched, and there is no server configuration involved for us as developers or managers of these Logic Apps. It is also server-less in the pricing sense, in that it is paid for in terms of how many actions our Logic Apps take.

Logic apps have a no code designer for rapid application creation.  It will give us an easy way, without writing code, to do integration in the cloud and automate it.  No need to go through hours or days to get setup.   With a simple user interface, it should help us to get started in a matter of minutes.  This simplification should help broaden the user base and make more people willing to use Azure.

How Logic App Works:

logic apps starts with a trigger whenever specific criteria meets or any event happened.Each time that the trigger fires, the Logic Apps engine creates a logic app instance that runs the workflow’s actions. These actions can also include data conversions and flow controls, such as conditional statements, switch statements, loops, and branching.

Benefit’s of Logic Apps:

  • Visually build workflows with easy-to-use tools.
  • Get started faster with logic app templates.
  • Connect disparate systems across different environments.
  • First-class support for enterprise integration and B2B scenarios.
  • Write once, reuse often.
  • Pay only for what we use.

Let’s take simple example with Microsoft one drive. Assume there is specific folder created on one drive and allow to upload different files like xml, json,word, ppt etc.Folder owner is more interested in specific files format not all files and want some notifications when ever specific file uploaded in one drive folder.

In above use case one drive and email client integration required and this problem can be solved by any programming techniques but required more configuration and development expertise But logic apps doesn’t required much expertise all of that.there are hundred’s of connector’s available to integrate with external tools.

Get Started:

Login on azure portal and select logic apps service under enterprise integration category.

L2.jpg

L8.jpg

There are so many templates available to start designing logic apps and select as per business requirement.select blank template for custom designing , here we will go with blank template.

L9.jpg

Once we create logic app than go to logic app designer and start designing the business workflows.

L3.jpg

Now start adding connectors as per the business requirement.Here we will select Microsoft one drive connector as staring point of logic app workflow.

To do so,click on “New Step” button and add new action,after that we will see a list of connectors.

L4.jpg

here is a list of connectors,we will search for Microsoft one drive to make connection with one drive.

L5.jpg

L6.jpg

Every connector has two type of options like trigger and actions.Trigger always be staring point of workflows and responding back on specific events on resources. In our case we are going to monitor our one drive folder.

L7.jpg

once we added one drive connector than we have to connect with valid credentials,here we have to use our Microsoft user id & password for one drive authentication.

L10.jpg

once we clicked on sign in button,we will redirect to Microsoft login page for login.

L11.jpg

Once we authenticate successfully then we are able to see all folder’s on one drive.Select any folder on which monitoring required,here i go with “Azure Testing Files” because all files uploaded in this folder.

L12.jpg

L13.jpg

Now add next step,Click on + sign and add conditional action.

L14.jpg

Conditions are similar to C# or any other language “if-Else” statements.

L15.jpg

First we have to define condition by taking input parameter’s from previous step which is one drive connector.we have to check uploaded file extension whether file is xml file or not.

L16.jpg

If above condition match than  write send mail functioanlity to notifying about uploaded xml file.Here we can see send mail logic defined inside the true condition with Gmail connector .

L17.jpg

Now we have to define some action for false condition,if conditional statement not matched with uploaded file.In this case we only monitor xml files.so if any other files uploaded than logic apps move such files from main folder to archive folder.

Let’s take one drive connector in false condition section and write  file archive logic,have a look complete file archival logic.

L19.jpg

Now we ready with folder monitoring workflow with logic app,let’s look complete designed logic app.

L20

Trigger the logic App:

To test the logic app,I have set the time frame as 10 second to trigger the logic apps that means in every 10 second one drive connector scan the one drive folder if any new file uploaded inside the folder,it automatically triggered and start executing complete workflow.

below is snapshot from one drive that contains two folders. One folder (“Azure Testing Files”) is used for uploading files and another folder (Archive Azure Testing) used for archive files.

L21.jpg

Verify True Condition,if Xml file uploaded then mail should send:

As of now both folder are empty.Now upload any xml file in “Azure Testing file” and we will see  logic app automatically trigger and detect this file and start executing all connectors. As per our condition file is xml than true section should execute and send mails to folder owner. Let’s catch-all events.

uploaded xml file to one drive folder.

L22.jpg

Now go to logic apps and see activity logs.

L23.jpg

if we open above highlighted details then visual designer pane will open with all connector execution status. here we can see each connector status in dept.

L24.jpg

As Gmail connector executed successfully then Gmail should send mail to folder owner.Below is received mail which is sent by logic app.

L25

Verify False Condition: If uploaded file is not xml file,then false block triggered.

Let’s upload other file format files (other than xml files) then true block will not execute and not send any email by Gmail connector.In this case false block will triggered and move file from uploaded folder to archive folder by one drive connector.

This time image file uploaded.

L26.jpg

See logic app execution details.

L27.jpg

After successfuly execution we can se uploaded file moved to archive folder from uploaded folder.

L28.jpg

Conclusion

Logic apps are not only about integration and orchestration, but also about connectivity to other services. These services can be Azure based, SAP applications or 3rd party solutions such as One-Drive and Dropbox: They can even be custom-built applications running on-premises, such as a web API.

Event Based Solution with Azure Event Grid & Logic Apps.

Event Based Solution with Azure Event Grid & Logic Apps.

Introduction

Event grid is new app-service in azure that connect applications together so that applications talk to each other in distributed environment. This way of working decouple application components, which enables more scalability, maintainability, and extensibility.

At the basic level it’s similar to a message queue service, like Azure Service Bus Topics, that enables a publish / subscribe model.

Azure Event Grid is a different kind of messaging service that’s built to enable event-based architectures like those use with Microservices architectures to be built more easily.

Azure Event Grid can be described as an event broker that has one of more event publishers and subscribers. Event publishers are currently Azure blob storage, resource groups, subscriptions, event hubs and custom events etc.  Subsequently, there are consumers of events (subscribers) like Azure Functions, Logic Apps, and WebHooks.

E1.jpg

 

Employee On boarding System Example:

Let’s take employee boarding system example which is very common and essential process to every organizations. So whenever new employees hired then there are some hiring formalities like save employee details in company database (azure database,on premises Database etc) and send and welcome email to employee to notified about joining dates and other formalities  and also send calendar invites for both parties (employee and HR) to remind the joining date.

There may be some other parties may include in this process like transport department,IT department etc to set up all the necessary things at the time of employee on boarding.

So employee information is common to all parties and on the basis of this information the have to execute some set of  actions  like email creation,Id card issue,IT assets arrangement and seat allocation,so there should be a mechanism that can broadcast the same information to all interested parties.

Here Azure event grid comes in picture and help us to solve this problem in very efficient manner and  logic apps removes all hurdles to integrate all external integrations like mail client,database base logic etc without much coding part.

Process Flow:

E3.jpg

There are below important sections to developed above solution:

  1. Mvc application to submit employee details.
  2. Setup azure event grid in azure
  3. setup logic apps in azure
  4. Add logic apps as subscriber to event grid
  5. Integrate all together from step 1 to step 4.

 

1 ) Create Employee On-boarding Portal (Mvc Application)

Primarily web application will receive all employee details from end-users and generate a json formatted message and send to azure event grid topic instead of directly inserted in azure database.Later this message broadcast to all its subscribers and processed.In our case logic app is topic subscriber hence message received by logic app and start processing and executing related actions like send mail,send calendar invite so on.

Here i am taking simple mvc application for demonstration with simple form.

e9.jpg

2 ) Setup azure event grid in azure

Login on azure portal and select new and search for event grid topic.Fill all the mandatory details like name,subscription,region and resource group.

e4.jpg

once we finish with event grid configuration then we will navigate to below user interface where we have to set up event subscriptions.In our case logic apps will be our event listener and need to map here but we will setup later in next steps.

e5.jpg

3 ) Setup Logic App Service:

Logic Apps helps us build, schedule, and automate processes as workflows so we can integrate apps, data, systems, and services across enterprises or organizations. Logic Apps simplifies how we design and create scalable solutions for app integration, data integration, system integration, enterprise application integration (EAI).

Choose “logic app ” service from available service in azure portal and fill all required information.

e6

e7

Now press create button and fill all required details like logic app name,resource group,region etc. logic app name should be unique throughout the globally and azure portal automatically suggest whether name is unique or not.

e8.jpg

now navigate to logic app and start designing process flow with logic app connector.Below is complete designed logic app flow and we will talk about each connector step by step.

e10.jpg

Let’s talk about each connector in details.

  • EventGrid Connector: logic apps have connector called event grid connector that able to connect with event grid and received all broadcast messages.Here it will received employee details that is json formatted messages  submitted by mvc application to event grid.

 e11.jpg

  • Parse Json Connector: This connector parse the message that received from event grid on the basis of provided message schema.Here output from event grid connector will become input for parse json connector.If message parse successfully than same message passed to next step that responsible to insert data in database

 e12.jpg

  • Sqlserver Connector: Sql connector enable us make communication with database.by using valid database credential we can make connection with database and select target tables in which message details need to store.

 E13.jpg

Once connection establish successfully with server then we can see all tables of that server.here we need to map our message properties with table columns to store message in sql tables.

when we will click on each property then message properties selection area enable to choose right property from all available.Below we can see there are multiple properties showing to select and we may select one or more properties to store in particular column,here i select employeeId to store in employeeid column.

e15.jpg

E14.jpg

  • Google Calender & Gmail Calender Connectors: we have successfully configured event grid ,message parsing and database connection.Now we have to set up two important task like send Calender invite and send emails.here we are adding both connectors as parallel branch so that execute simultaneously once message save successfully in database.

first we have to click on (+) symbol and choose “add parallel branch” and then select google Calender connector and again repeat above thing select Gmail connector.

         e16.jpg

Now we have to provide all required information like valid Gmail email id and other massage details.

E17.jpg

Now our logic app completely ready to use but one small integration still pending that is an integration of azure event grid logic apps.

4 ) Add logic apps as subscriber to event grid: Till above step we have created event grid, mvc application and logic apps.Now we have to add our logic apps as a subscriber to event grid so that every message can be broadcast to logic apps and trigger it.let’s see below steps:

  • go to newly created event grid topic from azure portal and click on “Event Subscription” button on top of the expanded view in event grid and some mandatory details as per below .

E18

To find subscriber endpoint,go to back our logic app.there is a option called “CalledBackUrl” and this is actual logic app calling end-point.we need to copied it and paste on above form.

e19.jpg

once we add logic app as a subscriber,it will showing in event grid subscriber’s list as per below:

e20.jpg

Great..our integration done till this step.Now little bit C# code need to add at our controller level to convert employee joining details in json message and send to event grid. let’s see how can we do it.

5 ) Mvc Application & Event Grid Integration:

Here mvc application works as message initiator and send employee details to event grid. by calling event grid topic  end-point as a service.once this message send to event grid then event grid broadcast same message to its subscriber,here logic app is our subscriber so logic app trigger and start executing it’s all components like save data in db and send mails to employee email id.

we can find event-grid endpoint from event grid detail page as per below

e21.jpg

look at the mvc controller from where application call event grid and sent message:

EmployeeController.cs


<span class="mceItemHidden">public class <span class="mceItemHidden"><span class="hiddenSpellError">EmployeeController</span></span> : Controller</span>
 {
 // GET: Employee
<span class="mceItemHidden"> public <span class="mceItemHidden"><span class="hiddenSpellError">ActionResult</span></span> Index()</span>
 {
 return View();
 }
<span class="mceItemHidden"> [<span class="mceItemHidden"><span class="hiddenSpellError">HttpPost</span></span>]</span>
<span class="mceItemHidden"> public <span class="mceItemHidden"><span class="hiddenSpellError">ActionResult</span></span> Index(<span class="hiddenSpellError">EmployeeModel</span> <span class="hiddenSpellError">employeeModel</span>)</span>
 {
<span class="mceItemHidden"> <span class="mceItemHidden"><span class="hiddenSpellError">TimeSpan</span></span> hours = new System.TimeSpan(0, 9, 0, 0);</span>
 employeeModel.DateOfJoining.Add(hours);

employeeModel.DateOfJoining = employeeModel.DateOfJoining.ToUniversalTime();
<span class="mceItemHidden"> <span class="mceItemHidden"><span class="hiddenSpellError">EventGridModel</span></span> <span class="hiddenSpellError">evmModel</span> = new EventGridModel();</span>
<span class="mceItemHidden"> <span class="mceItemHidden"><span class="hiddenSpellError">evmModel</span></span>.id = new Guid().<span class="hiddenSpellError">ToString</span>();</span>
 evmModel.eventType = "NewPost";
 evmModel.subject = "blog/posts";
 evmModel.eventTime = "2017-08-20T23:14:22+1000";
 evmModel.data = employeeModel;

<span class="mceItemHidden">List<span class="mceItemHidden"><span class="hiddenSpellError">egmList</span></span> = new List();</span>
 egmList.Add(evmModel);
<span class="mceItemHidden"> <span class="mceItemHidden"><span class="hiddenSpellError">SendMessageToEventGrid</span></span>(egmList);</span>
 return View();
 }

Here private method “SendMessageToEventGrid” called and in this method we have use event grid end-point to post json message.let’s look at implementation.

E22.jpg

Till now we have set up each component and now let’s see how things works when details submitted by mvc applcation.we will once details submitted successfully than message broadcast to all subscriber by event grid and logic app trigger and send Calender invite and email to employee.

Mvc application with employee details:

E23.jpg

Once we press create button,message send to event grid and event grid triggers logic app.below is logic app running status where we can see all connector execute successfully ( click on highlighted details and See green sign on each connector).

we can see the complete process took only 5 second to execute including all connector.

E24.jpg

Logic app running status in expend view:

E25.jpg

Below is email and calender invite from my inbox where we can see email successfully sent by logic apps.

E26

Calender Invite:

E27

 

I hope you like this..keep learning and sharing.