Monday, 8 August 2011

RabbitMQ Publisher Subscribe Example in Java on Ubuntu

To install RabbitMQ on Ubuntu is as simple as executing:

sudo apt-get install rabbitmq-server

Next we need to download the java client libraries as they are not included in the ubuntu package. You can find the libraries at Unzip the archive and include the jars in your classpath

First we need a way of creating connections to RabbitMQ and also a method to setup exchanges, queues and routing keys: Run the main method to setup our test queue.

Then create the publisher:

Then the consumer

The execute the main method on the Publisher and Consumer and watch the messages flow.

1 comment: