Back to Blog Archive

MuleSoft Connectivity with Microsoft Azure Service Bus

Posted on: July 2, 2019
Author:
Mary

This blog demonstrates how to connect MuleSoft with Microsoft Azure Service Bus via REST APIs and out-of-the-box MuleSoft Azure connector.

It covers the following:

  1. MuleSoft Azure Service Bus connector
  2. Message Publishing
  3. Message Subscription
  4. Message Deletion

Introduction

Microsoft Azure is a public cloud computing platform. This is an Infrastructure as a Service (IaaS) and Platform as a Service (PaaS) that can be used for services such as analytics, virtual computing, storage, networking, and much more.

For this blog, I have taken a simple use case of utilising Microsoft Azure platform, where a customer is already using IaaS/PaaS capability in their enterprise, and will show how Mule can seamlessly communicate with the Azure platform in data exchange and transformation to help the customer achieve their goals. 

What is Azure Service Bus?

Microsoft Azure Service Bus is a fully managed enterprise integration message broker. Service Bus is commonly used to decouple applications and services. It is a reliable and secure platform for asynchronous data and state transfer. Data is transferred between different applications and services using messages. A message can contain JSON, XML, or just text. 

Scenario

A customer receives a huge amount of data from various source systems. The Azure Service Bus receives and routes messages to the corresponding configured resources. These messages need to be transformed before distributing to different service endpoints or systems. 

Use Case

MuleSoft receives a message at the HTTP listener endpoint and publishes a message to Azure Service Bus Topic. Subscriber flow is enabled in MuleSoft to listen for the messages in the Topic. Event is triggered once the message is received in the Topic. The message is then subscribed by the MuleSoft flow, transformed as required and stored in the local file system for further processing.

This use-case is focusing on “Topics” and “Subscriptions”, enabling “one-to-many” relationships between publishers and subscribers.

Prerequisite

  1. Microsoft Azure Account
  2. Microsoft provides 12 months of free limited access to resources.

Creating a Microsoft Azure portal account is very simple. This account can be used for free and it enables you to utilise all the limited resources and explore the capabilities.

Microsoft Azure Account

Azure Service Bus creation

Search for “Service Bus” in the search bar. Select Service Bus and create new namespace as shown in the screenshot below.

Creating Microsoft Azure Service Bus

Fill all the fields and choose the pricing option. For this demo “Standard” pricing tier & free trial subscription is used.

How to connect MuleSoft with Microsoft Azure Service Bus

MuleSoft can connect to Azure Service Bus via “out-of-the-box” connectors available on the Anypoint Exchange; Azure itself also exposes REST APIs for the same purpose. In this blog, we will illustrate both ways of connecting to the Azure Service Bus.

MuleSoft Azure Service Bus connector

MuleSoft has several “out-of-the-box” connectors to connect to Azure Service Bus.

MuleSoft Azure Assets

MuleSoft Service Bus connector is used to post a message to the Topic. On the other hand, Azure REST API is utilised to subscribe to the message from the Topic.

Below are the steps to configure the Azure Service Bus connector.

  1. Shared access policies can be accessed from the Azure portal as highlighted below.

Azure Service Bus Connector String

2. Sample Endpoint URL.

Endpoint = sb://mule-test-test.servicebus.windows.net/
SharedAccessKeyName = RootManageSharedAccessKey
SharedAccessKey = N2qcKyyyyyyy5LLXXXXXXp6YCFYccccccIVZSjxuXw=


Azure Service Bus Configuration

3. Provide the Service Namespace, Shared Access Key Name and Shared Access Key in the Global element properties to configure the Azure Service Bus.

MuleSoft Azure Service Bus Connection Success

4. Click on Test Connection button to check the configuration details. Now all the Service Bus resources can be used within MuleSoft to leverage Azure Service Bus features.

Message Publishing

Postman is used to simulating messages from the source application.

Mule Event is triggered by the message received by the HTTP Listener.

Topic Flow

Postman Response

The received message is logged and published to the Service Bus Topic. Note the subscription count increases once the message is published.

Subscription Count

Message Subscription

Subscribing part in Mule is configured to exploit the Azure Service Bus API and delve into its capabilities. It is very simple to configure; below are a few screenshots of the HTTP request configuration and its properties.

Azure Host Configuration

Service Bus API Configuration

API uses SAS authentication. This is the primary security mechanism for Service Bus messaging.  In Mule 3.x, one way this can be accomplished is by using a combination of MEL function and Java utility. “getSasTokenWithPropertyValues” method defined here returns an authorisation Token and is used to establish a handshake between MuleSoft and the Azure Service Bus.

Subscription Flow

Mule HTTP Listener is configured to poll the Azure Service Bus Topic. Whenever the message is published to the Topic, subscription flow receives the message and checks for the valid data. If valid data is received then the message is logged and stored in the temporary folder in the file system. The message is then transformed and sent to a target application/system for further processing. Each message is removed from the topic once it is successfully processed. Log message confirms the file is stored in the local file system.

Console

Temporary File

Service Bus Message Deletion

Messages are removed from the Service Bus Topic using Azure Service Bus API. DELETE method is availed to perform this request.

Delete Configuration

Key properties required for this operation are SAS token, MessageID and LockToken. MessageID and LockToken can be accessed from the broker properties.

Summary

  1. MuleSoft connector is used to connect to Microsoft Azure Service Bus.
  2. Messages are published to Service Bus Topic using the MuleSoft Connector.
  3. MuleSoft utilises Azure Service Bus API capability to connect to Microsoft Azure Service Bus.
  4. MuleSoft uses DELETE method in Azure Service Bus API to delete the message from the Service Bus.
Author:
Mary

3 Comments for “MuleSoft Connectivity with Microsoft Azure Service Bus”

  1. Satish says:

    Good one

  2. Divya says:

    Informative…

  3. Volivattam says:

    Explained clearly that even a novice will understand better

Comments

Contact Us

Ricston Ltd.
Triq G.F. Agius De Soldanis,
Birkirkara, BKR 4850,
Malta
MT: +356 2133 4457
UK: +44 (0)2071935107

Send our experts a message

Need Help?
Ask our Experts!