RabbitMQ Clojure Example

RabbitMQ is a messaging application. You can relate it to similar solutions like ActiveMQ or MSMQ.

Essentially RabbitMQ is commonly-used, light, flexible and relatively fast AMQP solution. The Advanced Message Queuing Protocol (AMQP) is two layered (Functional and Transport) binary protocol specially tunned for message sending 😀 so to say – more information about AMQP and AMQ Architecture here. Furthermore RabbitMQ provides additional plugnins for STOMP, MQTT and bridge for ØMQ

ActiveMQ is more sophisticated, highly configurable and multi wire level protocol solution – currently possible protocols are AMQP, MQTT, OpenWire, REST, RSS and Atom, Stomp, WSIF, WS Notification, XMPP – more information here. The default protocol for ActiveMQ is OpenWire you can see/edit it in /apache-activemq-version/conf/activemq.xml

Installation of RabbitMQ (Ubuntu)

sudo apt-get install rabbitmq-server

Start the server

sudo rabbitmq-server

Check if it is running

sudo rabbitmqctl status

You should get result like:

[{pid,7060},
 {running_applications,[{rabbit,"RabbitMQ","2.8.6"},
                        {mnesia,"MNESIA  CXC 138 12","4.5"},
                        {os_mon,"CPO  CXC 138 46","2.2.7"},
                        {sasl,"SASL  CXC 138 11","2.1.10"},
                        {stdlib,"ERTS  CXC 138 10","1.17.5"},
                        {kernel,"ERTS  CXC 138 10","2.14.5"}]},
...

RabbitMQ Managment Plugin

This plugin provides simple but user-friendly graphical web-based interface, in which you can manage everything from users to queues, connections and channels :)

The enabling of plugin is quite easy. Just write the following line in the terminal

 rabbitmq-plugins enable rabbitmq_management

If everything goes fine you should have this up end rinning

http://localhost:55672/ 

The default authentication is:

Username: guest
Password: guest

And you can make new one simply by adding another user :)

Clojure example

Why Clojure? In the previous example that I did I used the old plain Java :) ActiveMQ Java example Here I decided to try something new :)

For the project creation/compile/dependency issues I used lein, because it is easy, understandable uses maven repositories without that pom.xml treat 😀 More information about lein here

Suorce code of the example:

project.clj file

(defproject rabbitmqquick "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [com.rabbitmq/amqp-client "3.3.4"]]
  :main rabbitmqquick.core)

The bold [com.rabbitmq/amqp-client “3.3.4”] part of the project.clj file handles the RabbitMQ dependency.

Into Maven pom.xml file it will looks like:

 

  com.rabbitmq
  amqp-client
  3.3.4

The example src itself implements ‘Paper-Rock-Scissors’-game and it is reversed engineered from the ActiveMQ Java example.

Source code: rabbitmqquick
For the delivery part I use tiny part of the langohr Clojure RabbitMQ API: https://github.com/michaelklishin/langohr. The API by itself is really awesome and you should totally go and check it out :)

  • http://twitter.com/monadic alexis richardson

    Nice post! Please note that RabbitMQ supports multiple protocols and not only AMQP. See MQTT and more here for example: http://www.rabbitmq.com/blog/category/new-features/

    • ki6i

      thanks, really good call, I did not know for the existence of these plugins :)