MuleSoft Integration With RabbitMQ

This article will explain in detail, how to integrate with RabbitMQ in MuleSoft and read messages from a queue.

Install and Setup RabbitMQ on Mac

In this section, I will explain how to install RabbitMQ on Mac, create a new queue and publish messages to the queue using the RabbitMQ portal.

Step 1: Install RabbitMQ.

brew install rabbitmq

Step 2: Start RabbitMQ Server.

Start RabbitMQ server in the foreground using the below command:

rabbitmq-server

Or start the server in the background using the below command:

brew services start rabbitmq

Step 3: Access RabbitMQ.

http://localhost:15672/

Access RabbitMQ

Enter both username and password as guest.

Step 4: Create New Queue.

http://localhost:15672/#/queues

Step 5: Publish Message in Queue.

http://localhost:15672/#/queues/%2F/order

Publish Message in Queue

Setup Mule Application 

In this section, I will explain how to create a new Mule application, listen on RabbitMQ queue, read a message from the queue.

Step 1: Create a new Mule 4 application:

Open Anypoint Studio click on File -> New -> Application Name (app-rabbitmq-orders).

Step 2: Install AMQP connector from the exchange:Install AMQP Connector From Exchange

Step 3: Create flow to read the message from order queue:Create Flow to Read Message

XML
 




xxxxxxxxxx
1
14


1
<?xml version="1.0" encoding="UTF-8"?>
2
 
          
3
<mule xmlns:amqp="http://www.mulesoft.org/schema/mule/amqp" xmlns="http://www.mulesoft.org/schema/mule/core"
4
 xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
5
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
6
http://www.mulesoft.org/schema/mule/amqp http://www.mulesoft.org/schema/mule/amqp/current/mule-amqp.xsd">
7
 <amqp:config name="AMQP_Config" doc:name="AMQP Config" doc:id="de2abf40-5ad2-4942-a874-99d12c486b4b" >
8
  <amqp:connection host="localhost" username="guest" password="guest" />
9
 </amqp:config>
10
 <flow name="app-rabbitmq-ordersFlow1" doc:id="aa37df28-a708-4d2d-8ee1-ee8ca0c4dfd0" >
11
  <amqp:listener doc:name="OrderQueueListener" doc:id="88ebbb66-8592-44f2-aee0-2d39ddb66d63" config-ref="AMQP_Config" queueName="order" ackMode="IMMEDIATE"/>
12
  <logger level="INFO" doc:name="RqbbitMQ Message" doc:id="4b2c8676-8baf-4ba2-adee-e28f0f1edc06" message="#[payload]"/>
13
 </flow>
14
</mule>


Step 4: Test the MuleSoft Application ListenerTest MuleSoft Application Listener


 

 

 

 

Top