Tallan's Technology Blog

Tallan's Top Technologists Share Their Thoughts on Today's Technology Challenges

How To Connect to an Azure Service Bus Queue Using MuleSoft’s HTTP Connector

Paul Gutierrez

On a recent project, I was given the requirements to connect MuleSoft to Microsoft’s Azure Service Bus Queue. Logically, the first thing I did was look at the available connectors MuleSoft offers on their exchange site. After a quick two second search I found that MuleSoft does indeed have a connector just for this. The problem I faced was that this connector ran on the enterprise edition of MuleSoft, which of course is a paid service. For my particular task I had to do this using Mule’s community edition so therefore this connector could not help me. Fortunately, there is a nice and easy way to connect to the Azure Service Bus Queue using just one HTTP connector. This blog post will show you how I was able to create this connector.

So the great thing about the Azure Service Bus Queue is that Microsoft exposes a RESTful API so that anybody can connect to it using HTTP. That fits perfectly with what we want to do in this scenario, as now we can easily swap out the Azure Service Bus Connector with an HTTP connector. Here is the step by step list of instructions you can use to build this HTTP connector:

  1. Add an HTTP Connector to your flow
  2. Add the following global configuration

OutboundHTTPConfig

  1. Replace the Host with the following: {Your Service Bus Namespace}.servicebus.windows.net
  2. Leave the protocol as HTTPS and the Port as 443
  3. Add the global configuration to your HTTP Connector
  4. Set the following configurations to your HTTP Connector

OutboundHttp

  1. Replace Path with the path of whichever request is needed. You can find the list of requests available here: https://msdn.microsoft.com/en-us/library/azure/hh780762.asp
    1. Note: This example is for sending messages to the queue. You can find the documentation for that request here: https://msdn.microsoft.com/en-us/library/azure/hh780786.aspx.
  2. Replace Method with the method of the request chosen in step 7.
    1. Note: This example is for sending messages to the queue therefore we used POST.
  3. Replace the Authorization header with your SAS token.
    1. Note: To learn how to generate the SAS token please read this blog post: https://blog.tallan.com/2016/01/13/how-to-generate-a-sas-token-for-an-azure-service-bus-queue-using-c/
  4. Save your project and run your mule flow.

In my example I used this HTTP connector in the following flow:

MulePOCFlow

The first connector in this flow is an inbound HTTP connector that accepts HTTP requests from my localhost. Below are the screenshots for the configurations:

InboundHttpConfig

InboundGlobalConfig

The second processor in the flow is a “Set Payload” transformer that sets the payload to: “Hello Paul’s World”. Below is the screenshot for the configuration:

SetPayload

The last outbound HTTP connector was the HTTP connector we built earlier in the blog post that will allow us to write messages to the queue. So in this example if we navigate to http://localhost:8081 the Mule flow will insert the “Hello Paul’s World” message into the queue.

Now if we open up postman, or any other similar tool, to send a request in order to receive the first item in the queue, we should get the “Hello Paul’s World” message we inserted earlier. Below is the screenshot of this result:

ReceiveMessageFromQueueResult

As we can see, it is quite easy to create an HTTP connector to communicate with the Azure Service Bus queue. Now we are able to connect to the Azure Service Bus Queue even if our requirements demand that we only use the community version of MuleSoft.

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>