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.
Join the DZone community and get the full member experience.
Join For FreeThis 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.
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.
Select Microsoft Service Bus: Azure Service Bus.
Provide Service Name, Shared Access Key Name, and Shared Access Key. Then, you can get it from the Windows Azure Service Bus connection information.
Perform the test connection and press OK.
Select Operation Queue send and provide the destination queue name.
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.
You can verify in the Azure Service Bus queue whether the message was received.
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.
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.
Here is the video tutorial.
Opinions expressed by DZone contributors are their own.
Comments