RabbitMQ is an open-source implementation of AMQP. If you don’t know what AMQP is, I encourage you to read about it on the official web site or the reference page. What I personally like in RabbitMQ/AMQP is
- AMQP is a free alternative to expensive TIBCO Randezvous.
- Functionality-wise AMQP is a superset of JMS.
- RabbitMQ is written in Erlang, which means fault-tolerance and reliability.
In this short blog entry I show how to install RabbitMQ on a *nix box, and verify that it’s working with a simple Groovy client.
Installing RabbitMQ server
Before installing RabbitMQ make sure you have Erlang environment set up. Run the following command and verify the output
$ erl -version Erlang (ASYNC_THREADS,HIPE) (BEAM) emulator version 5.10.1
I used to install RabbitMQ using apt-get command, which is convenient but always several versions behind. That’s why I switched to binary distribution installation. So here are the installation steps
$ sudo mkdir /opt/rabbitmq $ sudo chown -R rabbitmq /opt/rabbitmq $ cd /opt/rabbitmq $ wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.1.1/rabbitmq-server-generic-unix-3.1.1.tar.gz $ tar xf rabbitmq-server-generic-unix-3.1.1.tar.gz $ rm rabbitmq-server-generic-unix-3.1.1.tar.gz $ ln -s rabbitmq_server-3.1.1 rabbitmq
Append the following lines to ~/.bashrc
Enable web admin plugin
$ rabbitmq-plugins enable rabbitmq_management
Run the following command to verify server is starting
$ rabbitmq-server RabbitMQ 3.1.1. Copyright (C) 2007-2013 VMware, Inc. ## ## Licensed under the MPL. See http://www.rabbitmq.com/ ## ## ########## Logs: /opt/rabbitmq/rabbitmq/sbin/../firstname.lastname@example.org ###### ## /opt/rabbitmq/rabbitmq/sbin/../email@example.com ########## Starting broker... completed with 6 plugins.
Go to localhost:15672 in the browser. You should be able to login as guest/guest.
Groovy client is essentially Java client written in Groovy language. Here are the scripts for consumer and publisher in Groovy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Run consumer script in one terminal window
$ chmod 755 consumer.groovy $ ./consumer.groovy
and publisher script in another
$ chmod 755 publisher.groovy $ ./publisher.groovy
On the consumer window you should see Received message: Hello, world! text.
Now you just need to stop RabbitMQ server, and restart it in detached mode
$ sudo -u rabbitmq rabbitmq-server -detached