Wednesday, July 15, 2015

RabbitMQ client to publish JMS messages to WSO2 Message Broker 3.0.0 using Java

Hi All,

WSO2 Message Broker 3.0.0 is a distributed message broker that supports AMQP and MQTT.

This post will explain on how the RabbitMQ java client can be used to publish JMS messages to WSO2 Message Broker 3.0.0 with the help of Maven.

Add the RabbitMQ java client dependency

Add the following dependency the pom.xml file


The Code

Following is the implementation. See descriptions inline.

// The queue name
String queueName = "MyQueue";

// Creating the AMQP connection string for communication
ConnectionFactory factory = new ConnectionFactory();
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();

// Creating the queue
channel.queueDeclare(queueName, true, false, false, null);

// Binding the queue to "" exchange. Exchanges cannot be declared in WSO2 MB 3.0.0.
channel.queueBind(queueName, "", queueName);

// Message content to publish
String message = "This is a test message";

// Creating properties for the message.
AMQP.BasicProperties.Builder properties = new AMQP.BasicProperties.Builder();
properties.messageId("ID:" + String.valueOf(UUID.randomUUID()));

// Publishing message
channel.basicPublish("", queueName,, message.getBytes());

System.out.println("Message published : " + message);

// Closing the connection

Output on management console.

Click here to download the sample maven project.


No comments:

Post a Comment