Integration today is different than it was before with Logic Apps, Functions, API Management and the Service Bus. Integration service Logic App can be used to build a serverless integration solution. No more do you need to set up a server or procure one. An Azure Subscription and presto, you have access to every service Microsoft Azure bring.
Kent Weare got Steef-Jan Wiggers to talk about this on Middleware Friday. You can watch the live demo version of this example here.
A Logic App can be seen as a container you run a workflow in i.e. you can define a trigger followed by one of more actions in a visual designer. The trigger can be a Microsoft Managed API, a custom API App hosted in a Web App in the same region you want to call, or an API in API Management in your subscription. An action or actions that follow up on a trigger can be:
- Microsoft Managed API
- API App hosted in a Web App
- API in API Management in your subscription
- Logic Apps in the same region
- Azure Functions in the same region
Our scenario for Serverless Integration
In this blog, we will showcase a Logic App in combination with Functions and another Azure Service, the recently in preview available Cognitive Services. And we will build the solution completely in a browser and run it with Azure without using Visual Studio. Both Logic App Definition and Functions can be built using Visual Studio templates.
Our scenario is as follows — we have a Logic App with the following definition:
- Twitter trigger that polls every three minutes and filters tweet on the hashtag #trump
- The tweet text be sent to the Cognitive Service Sentiment API
- The result of the API will be evaluated by a Function
The outcome of the evaluation will determine if the tweet will be sent to slack channel good, moderate or bad.
The other component in this scenario is Slack, which is a SaaS solution that enables people to collaborate better or in this case can be used as an event channel viewer to observe the sentiment on twitter about the upcoming new US president.
Cognitive Service APIs
Cognitive Service API in Azure is one of the Platform services. It is a collection of API’s for Vision, Speech, Language, Knowledge and Search. You can discover each collection through the landing page. These API’s are in preview and can be found in the Azure Market Place.
You can have access to the services by creating them i.e. creating a Cognitive Services account that can be tied to one of the API’s.
By clicking Create a pane will appear, where you can name your Cognitive Service Account, specify your subscription and select which API you like to use. To support our scenario, we will select the Text Analytics API.
The final step before we create the account is to select the pricing tier. And to select the pricing tier that aligns with your requirements you can click view full pricing details.
Note: As you can see, you can select free tier to experiment with the API. The only location that can be selected is West US!
The Evaluation Function
The Function in our scenario will be provided with the input from the Cognitive Service API response. Azure Functions provide a serverless coding capability using a Browser and the piece’s code you write can run in Azure i.e. within a Function App. Hence you are getting an on-demand experience that is based on trigger by an event. An event can be a new message in a Service Bus queue, which can be a trigger for the function and the input is the message. You can connect to various data sources or messaging solutions thus making it easy to process and react to events. Azure Functions provide bindings to enable this so as a developer; you do not have worry too much about how the data flows to and from the Function. So, in a nutshell, Functions are based on triggers and bindings and code created in various languages (C#, F#, Node.js, Python, PHP, batch, bash, or any executable), that can simplify integration.
As developers, you can create HTTP-based API endpoints accessible by a wide range of applications, mobile and IoT devices. And it is scale-based and on-demand, so you pay only for the resources you consume through either a consumption plan or app price plan. The difference is that consumption is based on processing instance i.e. Function. And this plan is suitable if you have short running functions in a job or run intermitted. With an App price plan, your functions run in a dedicated VM and are always available. These price plans can be basic, standard or premium depending on your needs. And it is suitable if you have existing, under-utilized VMs that are already running other code or if you expect to run functions continuously or almost continuously.
Once a Function App is provisioned, you can add functions to it. For our scenario, we add a GenericWebHook-CSharp. We will rename the function to ProcessTextAnalysisScore and in the develop tab we see some generic default code, which we will change to the code below.
As you can see in the screen above, we can test our clicking test and provide a body, hit run and see the result in the output. The code can be developed and tested in a browser, hence we remain serverless and building this building block for our scenario.
The Logic App Definition
In a Logic App, we can define a workflow based on a trigger followed by one or more actions. And we can do this in a visual designer in a browser. Once we click on our Logic App, we can select a predefined template or an empty one. We choose the latter to create a flow based upon our scenario. Our trigger will be a Twitter tweet that filters on tweets with hashtag #trump. We follow up on the trigger by calling a Cognitive Service API. This will be our first action. To connect to our Cognitive Service API, we need to know the account name and key.
We can subsequently specify the text from the tweet we like to analyze and the language in our action.
The next step is using the score from the Cognitive Service API (detect sentiment) to be sent to the function that will evaluate the score and provide us with text containing Good, Moderate or Bad.
The outcome of the Function will be used for a type decision tree i.e. conditions in our Logic App definition. If the outcome (Body) our function is Good, then it will go to the IF YES branch where an action is defined to send the Tweet text and Tweeted by to Slack channel good. If that’s not the case, then the second condition will evaluate if the outcome equals Moderate and if that is true, then the IF YES branch will execute where an action is defined to send the Tweet text and Tweeted by to Slack channel moderate. If not, then the IF NO branch will execute where an action is defined to send the Tweet text and Tweeted by to Slack channel bad.
In Slack, I created a new team named sentimenttrump and within this team, three channels will be created. The tweet text and tweet by will become visible in the Slack channels of the sentimenttrump team.
Run the Logic App
Donald Trump is the new US president and there is a lot of activity around him. For instance, a lot of about him have the hashtag #trump. Therefore, it will not be a surprise that as soon as I enable the Logic App, there will be lot of tweets that will be processed. The screenshot below will tell you that.
Since there are massive number of tweets having #trump, the Logic App will be called a lot of times and some as you can see fail. The reason some fail is not that the Logic App can handle the workload, it is the Cognitive Service API that is not processing every call.
We have chosen a certain price plan, which only allows a specific amount of calls (see paragraph of Cognitive Services API). To be able to process the load, we will need a different pricing tier. The graphs of Cognitive Service API show that text analysis got a pretty big hit.
If we look at our Slack channel, we see that the channels good, moderate and bad are filled by tweets.
All tweets are scored and routed as such to the appropriate channel. A Slack member of SentimentTrump can observe the tweets in the channels.
You can watch the live demonstration of this Logic App by Steef-Jan Wiggers on Middleware Friday.
The pricing aspect is one of the key drivers of Azure. In our scenario, we have shown that we can build a solution fast, with little costs using consumption price plans and lower tier Cognitive Services API. With Azure, you can scale easily with Functions and Cognitive Services API if necessary. By placing every Azure artifact in one resource group, you can easily monitor the cost of the solution. Therefore, managing cost is easy in Azure.
Scale is an aspect that became apparent when running our solution. The Logic App could easily handle the load, but the Cognitive Service API could not since it was limited by the pricing tier. Hence, this service could not handle the load. Thus, you have to be aware of the load you are putting on your Logic App and know beforehand if the other artifacts involved in your solution are able to handle the load. In our scenario, the Azure Function and Cognitive Service API — if one of the services needs to scale out, the cost will increase. The Cognitive Service API will require a higher pricing tier to handle the load generated by the Logic App anticipating tweets with #trump.
Call to Action
In this blog, you have seen the power and ease of building a solution using a few building blocks in Azure:
- Azure Functions
- Logic Apps
- Cognitive Services API
And I encourage you to explore them and invest time to digest the technology, experiment yourself building your own type of solution. The demand in the future for the Azure integration type of solutions will only increase. Enterprises are currently embracing the cloud on a large scale. Hence, more hybrid and cloud integration solutions will be necessary. Moreover, the skills to build such solutions will be mandatory.[adrotate banner=”11″]