Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using the Microsoft Service Bus Connector With Mulesoft

DZone's Guide to

Using the Microsoft Service Bus Connector With Mulesoft

The service bus connector in Mule enables message integration with Windows Service Bus on-premise as well as with Azure Service Bus on the cloud.

· Integration Zone
Free Resource

Build APIs from SQL and NoSQL or Salesforce data sources in seconds. Read the Creating REST APIs white paper, brought to you in partnership with CA Technologies.

This connector supports the communication with queues, topics, and EventHubs through AMQP 1.0.

Features of Service Bus Connector

  • Send messages to queues, topics, and EventHubs with the support of AMQP.

  • Receive from queues and topic asynchronously.

  • Supports Windows Service Bus on-premise as well as Azure Service Bus on the cloud.

  • Rest management API like CRUD for queues, topics, subscriptions, and rules.

First, go through my article on how to create a service bus with Windows Azure. This article will give you a brief idea on how to create queues and topics in Azure cloud.

Now, we will walk through how to send and receive messages from the Windows Azure Service Bus queue.

Send Messages to the Windows Azure Service Bus Queue

Place the HTTP listener into the canvas and click to open the Properties console.

Click the green + and configure as follows:

  • Host: localhost.

  • Port: 8081.

  • Method: POST.

  • Path: servicebus.

Image title

Search and drag the Microsoft Service Bus Connector into the canvas. If the Microsoft Service Bus Connector is not found, then install it from Anypoint Exchange.

Click on the green to configure the Microsoft Service Bus Connector.

Image title

Select Microsoft Service Bus: Azure Service Bus.

Image titleProvide Service Name, Shared Access Key Name, and Shared Access Key. Then, you can get it from the Windows Azure Service Bus connection information.

Image title

Perform the test connection and press OK.

Select Operation Queue send and provide the destination queue name.

Image title

Test the Application

You can use Postman to send the request to Mule flow and Mule flow will send a message to the Azure Service Bus queue. The URL is http://localhost:8081/servicebus.

Image titleYou can verify in the Azure Service Bus queue whether the message was received.

Image title

Code:

<?xml version="1.0" encoding="UTF-8"?>
<mule
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns:microsoftservicebus="http://www.mulesoft.org/schema/mule/microsoftservicebus"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:spring="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/microsoftservicebus http://www.mulesoft.org/schema/mule/microsoftservicebus/current/mule-microsoftservicebus.xsd">
	<microsoftservicebus:azureConfig name="Microsoft_Service_Bus__Azure_Service_Bus" namespace="" userName="" password="" doc:name="Microsoft Service Bus: Azure Service Bus"/>
	<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
	<flow name="servicebusflowFlow">
		<http:listener config-ref="HTTP_Listener_Configuration" path="/servicebus" allowedMethods="POST" doc:name="HTTP"/>
		<microsoftservicebus:queue-send config-ref="Microsoft_Service_Bus__Azure_Service_Bus" destinationQueue="muletestqueue" doc:name="Microsoft Service Bus"/>
		<set-payload value="Message Sent to Queue" doc:name="Set Payload"/>
	</flow>
</mule>

Receive Messages From the Windows Azure Service Bus Queue

Search and drag the Microsoft Service Bus Connector in the message source area of the canvas. Configure in the same way as we have done above.

Select Operation Queue receive and provide the source queue.

Image title

This is how you can receive a message from the Azure Service Bus queue:

<?xml version="1.0" encoding="UTF-8"?>
<mule
	xmlns:file="http://www.mulesoft.org/schema/mule/file"
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns:microsoftservicebus="http://www.mulesoft.org/schema/mule/microsoftservicebus"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:spring="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/microsoftservicebus http://www.mulesoft.org/schema/mule/microsoftservicebus/current/mule-microsoftservicebus.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
	<microsoftservicebus:azureConfig name="Microsoft_Service_Bus__Azure_Service_Bus" namespace="" userName="" password="" doc:name="Microsoft Service Bus: Azure Service Bus"/>
	<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
	<flow name="servicebusflowFlow">
		<microsoftservicebus:queue-receive config-ref="Microsoft_Service_Bus__Azure_Service_Bus" sourceQueue="muletestqueue" doc:name="Microsoft Service Bus"/>
		<file:outbound-endpoint path="src/test/resources/out" responseTimeout="10000" doc:name="File"/>
	</flow>
</mule>

Similarly, you can configure the service bus topic to receive and send messages.

Now, you know how to send and receive messages from Azure Service Bus queue with Mulesoft.

The Integration Zone is brought to you in partnership with CA Technologies.  Use CA Live API Creator to quickly create complete application backends, with secure APIs and robust application logic, in an easy to use interface.

Topics:
mulesoft ,microsoft ,service bus ,azure ,tutorial

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}