Chapter 6. Working with Connectors in Logic Apps

 

Insufficient facts always invite danger.

 
 --Mr. Spock, Star Trek

Azure Logic Apps is a cloud-based service that you can use to create workflows that run in the cloud. It provides a way to connect your applications, data, and SaaS application using a rich set of connectors. Connectors get data in and out of a Logic App. It is created specifically to help you when you are connecting to different data source or applications and working with your data.

In this chapter, you will learn the following topics:

  • What are the different types of connector available in Logic Apps?
  • What are Workflow Triggers and Actions?
  • How can we create our own custom connector?

Traditionally, the two of mainstream integration scenarios are as follows:

  • EAI (Enterprise Application Integration)
  • B2B (Business-to-Business) integration using EDI protocols, such as EDIFACT or ANSI X12

However, in today's world, many systems and users need to integrate with SaaS-based systems and API-centric providers that handle everything from sales lead to invoicing, e-mail communication, and social media. Also, these systems or services can be well beyond corporate firewall.

As discussed in Chapter 5, Trigger Your First Logic App in Azure, Logic Apps provides a new way to build a business process that orchestrate data and services across cloud and on-premise data center. It is a browser-based workflow engine that makes integrating disparate applications and data sources from cloud to on-premises easy.

Also, modern integration is often not about enterprise systems and services only, but it has expanded to various mobile devices that drives the need of lightweight, modern API (connectors) primarily HTTP/REST-based protocols using JSON.

A connector is basically a type of API app that focuses on connectivity. Connectors get data in and out of a Logic App. It is created specifically to help you when you are connecting to different data source or applications and working with your data. It also aids you to extract and transform data from different enterprise applications or run complex business rules. Often in complex and advanced integration scenarios, these applications and data stores can span across cloud and on-premises resources.

Connectors can help to connect cloud and on-premises applications that are located behind a firewall using On-premises data gateway at: https://azure.microsoft.com/en-us/documentation/articles/app-service-logic-gateway-connection/.

Connectors make it easy to integrate systems and services and can also be used in order to manage authentication, monitoring, analytics, and more.

Essentially, all connectors are technically API Apps that uses a metadata format named Swagger (http://swagger.io/), REST as pluggable interfaces, and JSON as the data interchange format, which is easy for humans to read and write, and it's also easy for the systems to generate and parse data.

Connectors can act as a trigger or an action. A trigger starts a new instance of a workflow based on a specific event, such as the arrival of an e-mail or an insert of a new record in the table of a database or a change in your Azure storage account. Connector exposes some capability that after being triggered will be piped into other connectors (actions). By chaining these triggers and connectors, you can create potentially complex and powerful integrations between applications. We will discuss trigger and action in detail later in this chapter.

So, in a nutshell, Logic Apps are a collection of connectors that are primarily API Apps. These connectors can also be used to build PowerApps (https://powerapps.microsoft.com) and Flow (https://flow.microsoft.com). We will discuss about PowerApps and Flow later in the book. In this chapter, we will dig into the types of connector available from Microsoft, how can we use them in Logic Apps, and how can we create our own custom connector.

Categorizing Microsoft connectors

Connectors can be categorized into several groups based on the kind of operation they perform. These groups primarily include standard connectors and enterprise integration connectors.

Standard connectors

Standard connectors are the connectors created by Microsoft to work with SaaS applications or network services, and they include Office 365, SharePoint, Service Bus, Salesforce, SFTP, FTP/FTPS, and many more.

The following are the current list of available connectors created by Microsoft that are available as standard connectors. 

Standard connectors

This list will keep growing. Please refer to the link: https://azure.microsoft.com/en-us/documentation/articles/apis-list/ for the latest list of standard connectors.

Standard connectors

Some of these managed APIs can be used as is, such as Bing Translator, whereas others require configuration. This configuration is named a connection.

For example, when you use Office 365 connector, you need to create a connection that contains your sign-in token. This token will be securely stored and refreshed so that your Logic app can always call the Office 365 API. Alternatively, if you want to connect to your SQL or FTP server, you need to create a connection that has the connection string.

These actions are named as "ApiConnection" in the workflow definition language. The example here shows a connection that calls Office 365 to send an e-mail.

Standard connectors

The portion of the inputs that is unique to API connections is the "host" object. This contains two parts: "api" and "connection". The "api" has the runtime URL of where that managed API is hosted.

When you use an API, it may or may not have any connection parameters defined. If it doesn't, then no connection is required. If it does, then you will have to create a connection. When you create that connection, it'll have the name you choose and then you reference that in the connection object inside the host object. To create a connection in a resource group, call:

PUT https://management.azure.com/subscriptions/{subid}/resourceGroups/{rgname}/providers 

With the following body:

Standard connectors

Enterprise Integration connectors

These are primarily EAI and EDI connectors used for B2B scenarios with Logic Apps . As of Now we are having SAP and MQ connector available to connect the Logic Apps to enterprise system. This list is also growing and you can see lot of enterprise connector getting shipped with Logic Apps.

Enterprise Integration connectors

Connectors as triggers

A trigger specifies the calls that can initiate a run of your Logic App workflow. It's a common scenario where based on an event such as an arrival of an e-mail or new tweets that contain specific words, your workflow kicks off and take the appropriate action in response to the event.

Let's refer the example from the previous chapter, where the Logic App is using the Twitter API app and your workflow needs to perform an action based on new tweets that contain specific words. In this case, your Twitter connector can be used as trigger so that a new instance Logic App workflow instantiate.

Connectors as triggers

Here is the code view for the Twitter Connector as a trigger:

Connectors as triggers

All triggers can contain these top-level elements:

"<name-of-the-trigger>": { 
  "type": "<type-of-trigger>", 
  "inputs": { "<settings-for-the-call>" }, 
  "recurrence": { 
    "frequency": "Second|Minute|Hour|Week|Month|Year", 
    "interval": "<recurrence interval in units of frequency>" 
  }, 
  "conditions": [ "<array-of-required-conditions", ">" ], 
  "splitOn": "<property to create runs for>"
  "operationOptions": "<operation options on the trigger>" 
} 

There are the following two ways to initiate your Logic App workflow:

  • Poll triggers: Logic Apps polls your service (API App) endpoint at a specified interval to check for the new event. When new event data is available, a new instance of workflow runs with the event response data as input.
  • Push triggers:In this case, Logic Apps arenotified by the API App when an event occurs. A push trigger is implemented as a regular REST API that pushes notifications to Logic Apps by calling Workflow Service REST API (https://docs.microsoft.com/en-us/rest/api/logic/?redirectedfrom=MSDN), which is a Logic App as callable endpoint.

There is also native support for triggering Logic Apps via WebHooks, including the ability to define a synchronous response to the trigger. To create something that can be used as a push trigger, you need to expose an API endpoint to subscribe to your WebHook.

Note

A WebHook is an HTTP callback: an HTTP POST that occurs when something happens, a simple event-notification via HTTP POST.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset