RabbitMQ Notes

RabbitMQ is a broker that accepts messages from producers and delivers them to consumers. It routes, buffers or persists the messages according to rules. Everything about RabbitMQ is superb, from the design to the webpage documentation and tutorials. These notes will be commensurately sparser for it.

See RabbitMQ Tutorials: Introduction.


Terminology and concepts

Typically, the producer, broker and consumer do not live on the same host.

It's a core principle of RabbitMQ that a producer never sends any message directly to a queue, but to an exchange. The exchange determines what to do with the message. This depends on how it's supposed to be used:

Exchange types

Publish to a named exchange:

   channel.basicPublish( "myExchange", "", null, message );

Temporary queues

These are created unnamed, by calling queueDeclare() without a name. Once the consumer is disconnected, the queue is automatically deleted.

    String queueName = channel.queueDeclare().getQueue();

Bind a queue to an exchange:

    channel.queueBind( queueName, "myExchange", "" );

Visualize the mechanics...

This is a very simplified view.


Installation

Download from Downloading and Installing RabbitMQ. This amounts exactly to

  1. The Java client which consists of a bunch of JARs including and in particular, rabbitmq-client.jar, which you'll link at least to accomplish the tutorials noted above.
  2. The server, as a Debian or other download. This depends on other technology (Erlang) as shown below. Once installed, it's running and ready to accommodate the tutorial exercises.
    ~/Downloads/rabbitmq $ sudo dpkg -i rabbitmq-server_3.1.3-1_all.deb
    Selecting previously unselected package rabbitmq-server.
    (Reading database ... 181305 files and directories currently installed.)
    Unpacking rabbitmq-server (from rabbitmq-server_3.1.3-1_all.deb) ...
    dpkg: dependency problems prevent configuration of rabbitmq-server:
     rabbitmq-server depends on erlang-nox (>= 1:12.b.3) | esl-erlang; however:
      Package erlang-nox is not installed.
      Package esl-erlang is not installed.
    dpkg: error processing rabbitmq-server (--install):
     dependency problems - leaving unconfigured
    Processing triggers for man-db ...
    Processing triggers for ureadahead ...
    ureadahead will be reprofiled on next reboot
    Errors were encountered while processing:
     rabbitmq-server
    ~/Downloads/rabbitmq $ sudo bash
    ~/Downloads/rabbitmq # apt-get install erlang-nox
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    You might want to run 'apt-get -f install' to correct these:
    The following packages have unmet dependencies:
     erlang-nox : Depends: erlang-base but it is not going to be installed or
                       erlang-base-hipe but it is not going to be installed
              Depends: erlang-asn1 but it is not going to be installed
              Depends: erlang-corba but it is not going to be installed
              Depends: erlang-crypto but it is not going to be installed
              ...
              Depends: erlang-ssh but it is not going to be installed
              Depends: erlang-ssl but it is not going to be installed
              Depends: erlang-syntax-tools but it is not going to be installed
              Depends: erlang-tools but it is not going to be installed
              Depends: erlang-webtool but it is not going to be installed
              Depends: erlang-xmerl but it is not going to be installed
    E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
    ~/Downloads/rabbitmq # apt-get -f install
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    Correcting dependencies... Done
    The following extra packages will be installed:
      erlang-asn1 erlang-base erlang-corba erlang-crypto erlang-dev erlang-diameter erlang-docbuilder
      erlang-edoc erlang-erl-docgen erlang-eunit erlang-ic erlang-inets erlang-inviso erlang-mnesia
      erlang-nox erlang-odbc erlang-os-mon erlang-parsetools erlang-percept erlang-public-key
      erlang-runtime-tools erlang-snmp erlang-ssh erlang-ssl erlang-syntax-tools erlang-tools
      erlang-webtool erlang-xmerl libodbc1 libsctp1 lksctp-tools
    Suggested packages:
      erlang erlang-manpages erlang-doc xsltproc fop erlang-ic-java erlang-observer libmyodbc
      odbc-postgresql tdsodbc unixodbc-bin
    The following NEW packages will be installed:
      erlang-asn1 erlang-base erlang-corba erlang-crypto erlang-dev erlang-diameter erlang-docbuilder
      erlang-edoc erlang-erl-docgen erlang-eunit erlang-ic erlang-inets erlang-inviso erlang-mnesia
      erlang-nox erlang-odbc erlang-os-mon erlang-parsetools erlang-percept erlang-public-key
      erlang-runtime-tools erlang-snmp erlang-ssh erlang-ssl erlang-syntax-tools erlang-tools
      erlang-webtool erlang-xmerl libodbc1 libsctp1 lksctp-tools
    0 upgraded, 31 newly installed, 0 to remove and 9 not upgraded.
    1 not fully installed or removed.
    Need to get 21.1 MB of archives.
    After this operation, 36.0 MB of additional disk space will be used.
    Do you want to continue [Y/n]? y
    Get:1 http://archive.ubuntu.com/ubuntu/ precise/main erlang-base amd64 1:14.b.4-dfsg-1ubuntu1 [7,656 kB]
    Get:2 http://archive.ubuntu.com/ubuntu/ precise/main erlang-syntax-tools amd64 1:14.b.4-dfsg-1ubuntu1 [303 kB]
    Get:3 http://archive.ubuntu.com/ubuntu/ precise/main erlang-asn1 amd64 1:14.b.4-dfsg-1ubuntu1 [1,087 kB]
    Get:4 http://archive.ubuntu.com/ubuntu/ precise/main erlang-mnesia amd64 1:14.b.4-dfsg-1ubuntu1 [690 kB]
    Get:5 http://archive.ubuntu.com/ubuntu/ precise/main erlang-runtime-tools amd64 1:14.b.4-dfsg-1ubuntu1 [209 kB]
    Get:6 http://archive.ubuntu.com/ubuntu/ precise/main erlang-crypto amd64 1:14.b.4-dfsg-1ubuntu1 [43.7 kB]
    ...
    Get:25 http://archive.ubuntu.com/ubuntu/ precise/main erlang-ssh amd64 1:14.b.4-dfsg-1ubuntu1 [368 kB]
    Get:26 http://archive.ubuntu.com/ubuntu/ precise/main erlang-webtool amd64 1:14.b.4-dfsg-1ubuntu1 [42.1 kB]
    Get:27 http://archive.ubuntu.com/ubuntu/ precise/main erlang-tools amd64 1:14.b.4-dfsg-1ubuntu1 [542 kB]
    Get:28 http://archive.ubuntu.com/ubuntu/ precise/main erlang-nox all 1:14.b.4-dfsg-1ubuntu1 [19.0 kB]
    Get:29 http://archive.ubuntu.com/ubuntu/ precise/main erlang-dev amd64 1:14.b.4-dfsg-1ubuntu1 [499 kB]
    Get:30 http://archive.ubuntu.com/ubuntu/ precise/main libsctp1 amd64 1.0.11+dfsg-2 [8,102 B]
    Get:31 http://archive.ubuntu.com/ubuntu/ precise/main lksctp-tools amd64 1.0.11+dfsg-2 [48.3 kB]
    Fetched 21.1 MB in 40s (516 kB/s)
    Extracting templates from packages: 100%
    Selecting previously unselected package erlang-base.
    (Reading database ... 181516 files and directories currently installed.)
    Unpacking erlang-base (from .../erlang-base_1%3a14.b.4-dfsg-1ubuntu1_amd64.deb) ...
    Selecting previously unselected package erlang-syntax-tools.
    Unpacking erlang-syntax-tools (from .../erlang-syntax-tools_1%3a14.b.4-dfsg-1ubuntu1_amd64.deb) ...
    Selecting previously unselected package erlang-asn1.
    Unpacking erlang-asn1 (from .../erlang-asn1_1%3a14.b.4-dfsg-1ubuntu1_amd64.deb) ...
    Selecting previously unselected package erlang-mnesia.
    Unpacking erlang-mnesia (from .../erlang-mnesia_1%3a14.b.4-dfsg-1ubuntu1_amd64.deb) ...
    Selecting previously unselected package erlang-runtime-tools.
    Unpacking erlang-runtime-tools (from .../erlang-runtime-tools_1%3a14.b.4-dfsg-1ubuntu1_amd64.deb) ...
    Selecting previously unselected package erlang-crypto.
    Unpacking erlang-crypto (from .../erlang-crypto_1%3a14.b.4-dfsg-1ubuntu1_amd64.deb) ...
    ...
    Unpacking erlang-ssh (from .../erlang-ssh_1%3a14.b.4-dfsg-1ubuntu1_amd64.deb) ...
    Selecting previously unselected package erlang-webtool.
    Unpacking erlang-webtool (from .../erlang-webtool_1%3a14.b.4-dfsg-1ubuntu1_amd64.deb) ...
    Selecting previously unselected package erlang-tools.
    Unpacking erlang-tools (from .../erlang-tools_1%3a14.b.4-dfsg-1ubuntu1_amd64.deb) ...
    Selecting previously unselected package erlang-nox.
    Unpacking erlang-nox (from .../erlang-nox_1%3a14.b.4-dfsg-1ubuntu1_all.deb) ...
    Selecting previously unselected package erlang-dev.
    Unpacking erlang-dev (from .../erlang-dev_1%3a14.b.4-dfsg-1ubuntu1_amd64.deb) ...
    Selecting previously unselected package libsctp1.
    Unpacking libsctp1 (from .../libsctp1_1.0.11+dfsg-2_amd64.deb) ...
    Selecting previously unselected package lksctp-tools.
    Unpacking lksctp-tools (from .../lksctp-tools_1.0.11+dfsg-2_amd64.deb) ...
    Processing triggers for man-db ...
    Setting up erlang-base (1:14.b.4-dfsg-1ubuntu1) ...
    Searching for services which depend on erlang and should be started...none found.
    Setting up erlang-syntax-tools (1:14.b.4-dfsg-1ubuntu1) ...
    Setting up erlang-asn1 (1:14.b.4-dfsg-1ubuntu1) ...
    Setting up erlang-mnesia (1:14.b.4-dfsg-1ubuntu1) ...
    Setting up erlang-runtime-tools (1:14.b.4-dfsg-1ubuntu1) ...
    Setting up erlang-crypto (1:14.b.4-dfsg-1ubuntu1) ...
    ...
    Setting up erlang-ssh (1:14.b.4-dfsg-1ubuntu1) ...
    Setting up erlang-webtool (1:14.b.4-dfsg-1ubuntu1) ...
    Setting up erlang-tools (1:14.b.4-dfsg-1ubuntu1) ...
    Setting up erlang-nox (1:14.b.4-dfsg-1ubuntu1) ...
    Setting up rabbitmq-server (3.1.3-1) ...
    Adding group `rabbitmq' (GID 131) ...
    Done.
    Adding system user `rabbitmq' (UID 119) ...
    Adding new user `rabbitmq' (UID 119) with group `rabbitmq' ...
    Not creating home directory `/var/lib/rabbitmq'.
     * Starting message broker rabbitmq-server                                                                               [ OK ]
    Setting up erlang-dev (1:14.b.4-dfsg-1ubuntu1) ...
    Setting up libsctp1 (1.0.11+dfsg-2) ...
    Setting up lksctp-tools (1.0.11+dfsg-2) ...
    Processing triggers for libc-bin ...
    ldconfig deferred processing now taking place
    ~/Downloads/rabbitmq # dpkg -i rabbitmq-server_3.1.3-1_all.deb
    (Reading database ... 183665 files and directories currently installed.)
    Preparing to replace rabbitmq-server 3.1.3-1 (using rabbitmq-server_3.1.3-1_all.deb) ...
     * Stopping message broker rabbitmq-server                                                                               [ OK ]
    Unpacking replacement rabbitmq-server ...
    Setting up rabbitmq-server (3.1.3-1) ...
     * Starting message broker rabbitmq-server                                                                               [ OK ]
    Processing triggers for man-db ...
    Processing triggers for ureadahead ...