Administration tools

Being able to view and administer messages in a production environment is mandatory, especially when things go wrong. Fortunately, there is a tool available named Service Bus Explorer, which allows you to connect to a Service Bus namespace and administer the message entities. It can be downloaded at https://code.msdn.microsoft.com/windowsazure/Service-Bus-Explorer-f2abca5a .

Scenario

In this code sample, we will use our fictitious company Sunny Electricals to add purchase orders received from our website to a Service Bus via a Logic App.

Scenario

The Service Bus will be configured with two topics-one for purchase orders over $5000 and another topic for orders under $5000 to receive message from the Logic Apps.

Let's go ahead, step by step, to create the necessary artifacts for the Sunny Electricals purchase order solution. We will start with creating a new instance of Azure Service Bus namespace in the Azure Portal.

Log in to Azure portal using your official or personal Azure subscription at https://portal.azure.com/. On the Azure portal dashboard, click on More services and use the dropdown to navigate to Enterprise Integration and click on Service Bus.

Scenario

It will open a Service Bus window on the Azure portal dashboard. Click on Add to make a new instance of Azure Service Bus.

Scenario

Populate Service Bus details at the Create namespace blade. Give a proper name to your Service Bus, select pricing tier based on your usages and then the resource group in which you want to run your service. If you do not have existing resource group or you require to create separate resource group, then select Create new resource group. Click on Create at the bottom of the blade to get a new instance of Service Bus.

Scenario

This will create a new instance of Service Bus in the Azure. Click on the newly created Service Bus to open the Service Bus overview window.

To create Azure Service Bus, you can also use Microsoft Azure PowerShell scripting. The use of PowerShell will automate your deployment process, and you do not need to go through Azure portal to create a Service Bus namespace manually for each different environment. To install and configure Azure PowerShell, you can follow the instructions available at the MSDN link shared here: https://docs.microsoft.com/en-us/powershell/azureps-cmdlets-docs/.

To create a new Azure Service Bus namespace in Azure using PowerShell, you can use the New-AzureSBNamespace PowerShell cmdlet command.

Parameter Set: Default

New-AzureSBNamespace [-Name] <String> [[-Location] <String> ] [[-CreateACSNamespace] <Boolean> ] [-NamespaceType] <NamespaceType> {Messaging | NotificationHub} [ <CommonParameters>]

Note

For more description of each of the parameters, you can refer to the MSDN link at: https://docs.microsoft.com/en-us/powershell/servicemanagement/azure.compute/v1.6.1/New-AzureSBNamespace?redirectedfrom=msdn.

For this solution, create two topics within Azure Service Bus to hold invoice details. Here, we have created PremiumInvoice topic and Invoice topic within the Sunny Electricals Service Bus namespace.

The following steps demonstrate how to create the PremiumInvoice topic; you can follow the same instructions to create the Invoice topic.

Scenario

While creating topics, there are certain properties that need to be populated based on your requirement and usage. The list is shown in the following table:

Properties

Description

Name

The name of the topic

Max size

The total size of the message in the topic/queue

Message time to live

This is the duration of time after which the message in Service Bus expires, Messages older than their TimeToLive value will expire and no longer be retained and moved to dead-letter subqueue.

Enable duplicate detection

By enabling duplicate detection, if any duplicate message is posted to the Service Bus topic, the service will automatically ignore the message

Enable partitioning

Enabling partitioning will give you multiple message broker capability, and incoming messages can be stored in multiple message stores.

Once you have created both the topics, verify the topics/queues by clicking the Topics or Queues section within the Service Bus Overview blade.

Scenario

This is not completed yet; for Logic Apps to push or pull messages in or out of the Service Bus topic, you need to define a topic subscription. The creation of a subscription is necessary to facilitate the publish/subscribe mechanism that is supported by Azure Service Bus.

For this solution, you need to create two subscriptions: one is for Premiuminvoice andother for  Invoice topic.

The following table hold the list of properties which you require to populate in order to create subscription for the topic.

Properties

Description

Name

The name of the subscription for the topic

Message time to live

Time duration after which the message in Service Bus topic expires.

Lock duration

Sets the duration of a peek lock; that is, the amount of time that the message is locked from other receivers.

Move expired message to dead-letter sub queue

By enabling dead-letter subqueue, you explicitly move expired message to dead-letter queue and expired message is not lost

Move message that cause filter evaluation exception to the dead-letter subqueue

Determines how Service Bus handles a message that causes an exception during a subscription filter evaluation. If true, the message that caused the exception is moved to the subscription's dead-letter queue. Otherwise, it is discarded.

Enable Session

If set to true, the topic is session aware and only session receiver is supported. Session-aware topics are not supported through REST. The default value is false 

PremiumInvoice and Invoice topic subscription creation

PowerShell can automate these manual tasks to create topics and associated subscriptions.

PremiumInvoice and Invoice topic subscription creation

You can follow the steps and scripts available at the following Microsoft blog post : https://blogs.msdn.microsoft.com/paolos/2014/12/02/how-to-create-service-bus-queues-topics-and-subscriptions-using-a-powershell-script/.

PremiumInvoice and Invoice topic subscription creation

Up to now, we have done all the setup steps required for the Service Bus setup. We will move a step ahead and create a new Logic App in Azure portal, which will use the HTTP trigger to get the invoice message from the web App. We will use similar steps as described in previous chapters to create a new sunnyElectricalsGetInvoice Logic App through Azure portal or with Visual Studio 2015.

PremiumInvoice and Invoice topic subscription creation

The Logic App workflow is quite simple and easy to implement. We are receiving an HTTP request for an invoice in the application/JSON format. If you pass content type in another format, such as application/text or xml, then convert the content type to application/JSON within logic workflow using expression language to get the desired JSON string.

Note

By setting the content type to application/JSON in the request HTTP header, Logic App will convert the JSON to a typed object using the provided JSON schema.

Copy the JSON request schema in the body section of Request Http trigger.

PremiumInvoice and Invoice topic subscription creation

Save the Logic App by clicking on the Save button on the top. This will generate the HTTP endpoint, which will be used for application integration and test.

PremiumInvoice and Invoice topic subscription creation

If you do not have the JSON Schema, you can use sample request JSON payload to generate the JSON Schema. It is quite simple as demonstrated here. For this sample, we have used JSON message shown in the following table:

{
"Invoice": {
"InvoiceId": "SE0034BD001",
"JobId": "SE005",
"Status": "PENDING",
"UserId": "BD001",
"UserName": "JOHN MAC",
"UserEmail":"[email protected]",
"Date": "04/01/1986",
"Amount": 8000,
"Comments": "PENDING INVOICE",
"Address": "NZ"
}
}

Once you populated the trigger section with the correct JSON schema, you can construct the workflow with decision shape (the Condition Amount is greater than 5000).

PremiumInvoice and Invoice topic subscription creation

While configuring send to topic action, there are some mandatory fields that need to be populated with correct values, which include Queue/Topic name, Content, and proper connection information for the Service Bus.

PremiumInvoice and Invoice topic subscription creation

So, we are done with solution design for our first logic App, which is invoked by the HTTP request and by sending the invoice message to two different Service Bus Topics based on the amount.

To test this solution, you can use Postman and Azure Service Bus Explorer. You can download Service Bus Explorer from the MSDN code repository here: https://github.com/paolosalvatori/ServiceBusExplorer.

After downloading the code, you need to build and run the Azure Service Bus Explorer project. You also need to provide correct connection information in Azure Service Bus Explorer, which you can get from Azure portal or a PowerShell command.

PremiumInvoice and Invoice topic subscription creation

You need to post some sample request through Visual Studio test client or Postman, and you can verify the run result in Azure portal and Service Bus Explorer.

PremiumInvoice and Invoice topic subscription creation

PremiumInvoice and Invoice topic subscription creation

In the solution described so far, we have gone step by step through creating Logic Apps, Service Bus and creating different topics for Premium and general customers. We have also seen how to use Azure Service Bus Explorer. By doing this exercise, you now have some hands-on experience creating Azure Service Bus artifacts via Azure portal directly and also creating queues and topics. This sample also explains how you can use a Logic App to push data to Service Bus topics or queues.

In the next sample, we will be polling the Premium topic and doing some parallel processing on messages received from the topic.

In integration, the parallel action is one of the most common integration design patterns, which can be used widely and in different use cases.

Let's create a new Logic App with the name GetPremiumCustomer and associate the trigger on Service Bus topic.

PremiumInvoice and Invoice topic subscription creation

Populate the Service Bus topic trigger with the correct topic name and subscription. You can fetch the list of parameters through portal using Azure PowerShell scripting.

PremiumInvoice and Invoice topic subscription creation

After defining the trigger for Logic App, we have a set of two parallel actions that will be performed on the incoming message. First action is to send the message to the external HTTP listener endpoint and second is to store the premium customer details in the Azure SQL database.

PremiumInvoice and Invoice topic subscription creation

For the parallel processing of actions, you need to go through the code page of Logic Apps and define two actions in parallel, which will be invoked after the receiving message from service bus topic.

PremiumInvoice and Invoice topic subscription creation

In this sample, we have used RequestBin: https://requestb.in/ to intercept the web request.

To test this solution, you can verify the Logic App run and check requestbin for the HTTP intercepted request.

PremiumInvoice and Invoice topic subscription creation

PremiumInvoice and Invoice topic subscription creation

To verify the latency of the running logic apps, you can configure the matrix within the specified Logic Apps.

PremiumInvoice and Invoice topic subscription creation

By doing the second sample, we have shown how you can trigger a Service Bus topic or queue from Logic App and can perform the parallel processing of multiple action within Logic Apps.

Note

You can extend the parallel processing to work with scatter gather pattern within Logic Apps.

For more information refer to: http://www.enterpriseintegrationpatterns.com/patterns/messaging/BroadcastAggregate.html.

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

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