Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Adding Contents Table

Table of Contents

Accessing RabbitMQ

Web Based Management UI

The easiest way to configure RabbitMQ is via the web based ManagementUI. Although useful for ad hoc monitoring and administration, this tool is not suitable for repeatable configuration in a DevOps environment. The Management UI requires the rabbitmq RabbitMQ 'Management Plugin'. Not every RabbitMQ deployment will have the 'Management Plugin' installed.

...

This endpoint is typically at http://<rabbit-server>:<rabbit-port>:/api. The REST API is flexible - it can be used by any client that talks HTTP but is not human friendly. The output is very verbose. Example : . This example gets information about the queue called 'q.type1' from the virtual host 'vhMon01'.

Code Block
titleusing rabbit REST API
curl -u $RBT_USER:$RBT_PASSWD http://localhost:15672/api/queues/vhMon01/q.type1

...

Documentation about the REST API is available at 'http://<rabbit-server>:<rabbit-port>/api/index.html'

...

rabbitmqadmin Command Line Tool

The 'rabbitmqadmin' cli  command line tool can be downloadable downloaded from each rabbit RabbitMQ server that has the 'Management Plugin' installed. It can be downloaded from 'http://<rabbit-server>:<rabbit-port>/cli/rabbitmqadmin' internally, it . It talks to the RabbitMQ installation server using the Rabbit Rest API. The rabbitmqadmin tool uses requires python as a pre-requisite. The tool can be used to create/declare, examine and delete the following rabbit resources. The rabbitmqadmin tool can be pointed at a rabbit installation RabbitMQ server on another machine using optional --host and --port parameters. 

It is reasonably straightforward to perform most RabbitMQ configuration tasks using the rabbitmqadmin tool.

...

rabbitmqctl Command Line Tool

The following text is copied from this excellent stackoverflow answer

...

rabbitmqadmin is more for general admin, you have the same features you have in the management UI, you can also retrieve the node statistics.

Overview of RabbitMQ Resources

Most message related resources (queues/exchanges) in RabbitMQ are scoped to a vhost(Virtual Host). A vhost is just a namespace holder. It has a name. The default vhost is named '/'.

The following resources belong to a vhost (namespace)

  • exchanges - where a producer sends messages to
  • queues - where a consumer gets messages from
  • bindings - these help route messages between exchanges and queues/other exchanges
  • policies - these are useful for "extra" behaviours - for example when messages are not processed or not routed.

The following resources DO NOT belong to a vhost

  • vhosts ( they are not hierarchical )
  • users - each user can be associated with
    • a password (optional)
    • a list of  Management UI tags - limits what a user can do when logged into Management UI console.
    • three regexp patterns one each for read / write / configure
    • topic permissions (required for MQTT/ STOMP? - not required for TIS)

RabbitMQ ResourcesImage Removed

Using Rabbitmqadmin CLI tool to configure RabbitMQ

The rabbitmqadmin tool can be used to individually create queues/exchanges etc. This works okay but you'd quickly end up with large shell scripts containing lists of separate rabbitmqadmin commands.

A better approach is to use the Management UI to create a Rabbit Configuration of exchanges/queues etc. First use the Management UI to create a fresh vhost (virtual host).

You can declare(create) and delete vhosts in the management UI. Switch to that virtual host and create the desired rabbit configuration by hand. You can send test messages to the exchanges in your configuration and check that the messages are routed as expected. When you are happy with your configuration you can export the Rabbit Configuration for just for that vhost.

Rabbitmqadmin Configuration Files

A rabbitmqadmin config file either be associated with a single vhost or all vhosts. If you export a rabbitmqadmin file for a single vhost - it will not contain any user information. Users do not belong to a specific vhost. If you export rabbitmqadmin file for ALL vhosts - then it will contain the users, the vhosts and the permissions linking users to vhosts too.

Don't forget : when you export a rabbit config file - you are only exporting the configuration of the exchange/queues etc - YOU ARE NOT EXPORTING THE MESSAGES !

When you import a rabbit config file into a vhost - it adds to whatever's already there. To reset a vhost to the contents of a config file, best perform the following steps:

  1. delete the vhost - ( be careful - this will delete any messages too )
  2. declare (create) the vhost - it will be empty
  3. import the config into the vhost

rabbitmqadmin commands

This section shows examples of several rabbitmqadmin commands. To use rabbitmqadmin you need a username/password. Typically each rabbitmq installation will define a single "administrator".

The following rabbitmqadmin commands assume the following, pre-defined, environmental variables:

...

Create a new vhost

Code Block
titleCreate a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD declare vhost name=vhMon01
vhost declared

List all vhosts

...

titleListing vhosts

...

rabbitmq-plugins Command Line Tool

One of the limitations of the rabbitmqadmin tool is that you can't use to to check which plugins have been installed. To look at which plugins have been explicitly enabled within RabbitMQ - you have to use the rabbitmq-plugins command which is available on the RabbitMQ server (and not available remotely over http)


Code Block
firstlineShow explicitly enabled RabbitMQ plugins
rabbitmq-plugins list -e
Listing plugins with pattern ".*" ...
 Configured: E = explicitly enabled; e = implicitly enabled
 | Status: * = running on rabbit@d2c02ccab9ce
 |/
[E*] rabbitmq_management       3.7.18
[e*] rabbitmq_management_agent 3.7.18
[e*] rabbitmq_web_dispatch     3.7.18

Overview of RabbitMQ Resources

Most message related resources (queues/exchanges) in RabbitMQ are scoped to a Virtual Host(vhost). A Virtual Host is just a namespace holder. It has a name. The default Virtual Host is named '/'. Virtual Hosts don't have have have a name starting with '/'.

The following resources belong to a Virtual Host (namespace)

  • Exchanges - where a producer sends messages to
  • Queues - where a consumer gets messages from
  • Bindings - these help route messages between exchanges and queues/other exchanges
  • Policies - these are useful for "extra" behaviours that can apply to multiple resources in one place - for example when messages are not processed or not routed.

The following resources DO NOT belong to a Virtual Host (vhost)

  • Vhosts ( they are not hierarchical )
  • Users - each user can be associated with
    • a password (optional)
    • a list of  Management UI tags - these tags limit what a user can do when logged into Management UI console.
    • three regexp patterns one each for read / write / configure
    • topic permissions (required for MQTT/ STOMP? - not required for TIS)

RabbitMQ ResourcesImage Added

Using rabbitmqadmin Command Line Tool to configure RabbitMQ

The rabbitmqadmin tool can be used to create individual queues/exchanges etc. This works okay but you'd quickly end up with large shell scripts containing lists of separate rabbitmqadmin commands.

A better approach is to use the Management UI to create a RabbitMQ configuration of exchanges/queues etc. First use the Management UI to create a fresh vhost (virtual host).

You can declare(create) and delete vhosts in the management UI. Switch to that virtual host and create the desired RabbitMQ configuration by hand. Within the ManagementUI you can send test messages to the exchanges in your configuration and check that the messages are routed as expected. When you are happy with your configuration, you can export the RabbitMQ Configuration for just for that vhost.

RabbitMQ Configuration Files

A RabbitMQ config file either be associated with a single vhost or all vhosts. If you export a RabbitMQ configuration file for a single vhost - it will not contain any user information. Users do not belong to vhosts. If you export a RabbitMQ configuration file for ALL vhosts - the exported file will contain all the users, all the vhosts and all the permissions linking users to vhosts.

Don't forget : when you export a RabbitMQ configuration file - you are only exporting the configuration of the exchange/queues etc - YOU ARE NOT EXPORTING THE MESSAGES !

When you import a RabbitMQ configuration file into a vhost - it adds to whatever's already there. To reset a vhost to the contents of a config file (and nothing else), best perform the following steps:

  1. delete the vhost - ( be careful - this will delete the vhosts resources and the messages held on the vhosts queues too )
  2. declare (create) the vhost - it will be empty - (expect for the standard amq queues/exchanges)
  3. import the config into the vhost

rabbitmqadmin commands

This section shows examples of several rabbitmqadmin commands. To use rabbitmqadmin you need a username/password. A fresh install of RabbitMQ typically comes with an 'admin' user.

The following rabbitmqadmin commands assume the following, pre-defined, environmental variables:

NameDescription
RBT_USERrabbit username
RBT_PASSWDrabbit password
VHOSTthe vhost being used

Executing commands against a remote RabbitMQ server

If you want to run rabbitmqadmin and point to a RabbitMQ server which is not localhost:15672,  the rabbitmqadmin supports these 2 optional parameters:


Code Block
titlerabbitmqadmin optional parameters
--host=HOST, -H HOST    connect to host HOST [default: localhost]
--port=PORT, -P PORT    connect to port PORT [default: 15672]

Create a new vhost

Code Block
titleCreate a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD declare vhost name=vhMon01
vhost declared

List all vhosts

Code Block
titleListing vhosts
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD list vhosts
+---------+----------+
| name    | messages |
+---------+----------+

Delete a vhost

When a vhost is deleted, it deletes all the exchanges/queues and messages it contains)

Code Block
titleDelete a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD delete vhost name=vhMon01
vhost deleted

Import Rabbit Configuration File into a vhost

Code Block
titleImport a config file for a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST import rabbit_config_for_vhost.json
Uploaded definitions from "localhost" to rabbit_config_for_vhost.json. The import process may take some time. Consult server logs to track progress.

Export Rabbit Configuration for a vhost to a json config file

Code Block
titleExport a config file for a vhost

| /       |   0      |
| vhMon01 |   6      |
+---------+----------+

Delete a vhost

When a vhost is deleted, it deletes all the exchanges/queues and messages it contains)

Code Block
titleDelete a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD delete --vhost name=$VHOST export rabbit_config_for_vhost_exp.json
Exported definitions for localhost to "rabbit_config_for_vhost_exp.json"

Purge all messages on queues for a vhost

This is a single (but long) unix command line

Code Block
titlePurge Vhost Queues
theQueues=$(vhMon01
vhost deleted

Import Rabbit Configuration File into a vhost

You might want to ensure the vhost doesn't have any resources in it as this command adds to whatever's in the vhost already.

Code Block
titleImport a config file for a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list queues -f bash); for queue in $theQueues;\
do rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST purge queue name=$queue; done

List the queues associated with a vhost

This can be used to quickly check if there are any queued messages before RabbitMQ admin.

To show queues of
Code Block
title
import rabbit_config_for_vhost.json
Uploaded definitions from "localhost" to rabbit_config_for_vhost.json. The import process may take some time. Consult server logs to track progress.

Export Rabbit Configuration for a vhost to a json config file

Note: by using the --vhost option - you are exporting configuration for a single vhost.

Code Block
titleExport a config file for a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list queues
+----------------------+----------+
|         name         | messages |
+----------------------+----------+
| q.type1              | 0 export rabbit_config_for_vhost_exp.json
Exported definitions for localhost to "rabbit_config_for_vhost_exp.json"

Purge all messages on queues for a vhost

This is a single (but long) unix command line

Code Block
titlePurge Vhost Queues
theQueues=$(rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list queues -f bash); for queue in $theQueues;\
do rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST purge queue name=$queue; done

List the Exchanges associated with a vhost

Code Block
titleTo show exchanges of a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list exchanges
+--------------------+---------+
|       | | q.type2name        |  type    | 0  |
+--------------------+---------+
|      | | sys.q.audit.01       | 0     | direct  |
| sys.q.dead.letter.01 | 0amq.direct         | direct  |
| sys.q.unrouted.01amq.fanout    | 0    | fanout  |
| +----------------------+----------+

List the exchanges associated with a vhost

Code Block
titleTo show exchanges of a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list exchanges
+--------------------+---------+
| amq.headers        | headers |
| amq.match       name   | headers |
| amq.rabbitmq.trace | topic type  |
|
+--------------------+---------+
|      amq.topic          | topic   |
| ex.entry.point     | fanout  |
| ex.router.main     | directtopic   |
| amqsys.ex.directaudit         | directfanout  |
| amq.fanout        sys.ex.dead.letter | fanout  |
| amq.headers    sys.ex.unrouted    | headersfanout | |
amq.match          | headers |
| amq.rabbitmq.trace | topic   |
| amq.topic +--------------------+---------+

List the Queues associated with a vhost

This can be used to quickly check if there are any queued messages before RabbitMQ admin.

Code Block
titleTo show queues of a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list queues
+----------------------+----------+
|         name         | topicmessages   |
| ex.entry.point|
+----------------------+----------+
| q.type1          | fanout  | | ex.router.main0     | topic   |
| sys.ex.auditq.type2        | fanout  | | sys.ex.dead.letter | 0 fanout  | | sys.ex.unrouted    |
| sys.q.audit.01       | 0        |
| sys.q.dead.letter.01 | 0        |
| sys.q.unrouted.01    | fanout 0        |
+----------------------+----------+

List the

...

Bindings associated with a vhost

Code Block
titleTo show the policies associated with bindings of a vhost
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list policiesbindings
+---------+------------+-----------+-----------+----------------------+
|       source       |     destination      |     routing_key      |
+-------------------------+-----------------------+--------------+----------+
|   vhost  |         name      | q.type1   | apply-to           | q.type1              |
|                    | definitionq.type2              | q.type2              |
|                pattern    | priority |
+---------+-----------------------+-----------+----------------------------------------------------------------------+--------------+----------+
| vhMon01 | unroutedMessagePolicy | exchanges | {"alternate-exchange": "sys.ex.unrouted"}     sys.q.audit.01       | sys.q.audit.01       |
|                    | sys.q.dead.letter.01 | sys.q.dead.letter.01 |
|                    | sys.q.unrouted.01    | sys.q.unrouted.01    |
| ex.entry.point     | ex.router.main       |                 | ^ex.router.* | 0  |
| ex.entry.point    | | vhMon01sys.ex.audit | messageTimeoutPolicy  | queues    | {"message-ttl": 30000, "dead-letter-exchange": "sys.ex.dead.letter"} | ^q.*         | 1        |
+---------+-----------------------+-----------+----------------------------------------------------------------------+--------------+----------+

List the bindings associated with a vhost

Code Block
titleTo show bindings of a vhost
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list bindings
+--------------------+----------------------+----------------------+
||
| ex.router.main     | q.type1              | type1                |
| ex.router.main     | q.type2              | type2                |
| sys.ex.audit       | sys.q.audit.01       |            source       |   |
 destination      || sys.ex.dead.letter | sys.q.dead.letter.01 |                      |
| sys.ex.unrouted    | sys.q.unrouted.01    |                routing_key      |
+--------------------+----------------------+----------------------+
|                    | q.type1              | q.type1              |
|                    | q.type2              | q.type2              |
|  

List the Policies associated with a vhost

Code Block
titleTo show the policies associated with a vhost
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list policies
+---------+-----------------------+-----------+----------------------------------------------------------------------+--------------+----------+
|  vhost  |         name          | apply-to  |     | sys.q.audit.01       | sys.q.audit.01       | |        definition            | sys.q.dead.letter.01 | sys.q.dead.letter.01 |
|                    | sys.q.unrouted.01    | sys.q.unrouted.01pattern    | | ex.entry.point     | ex.router.main       |                      |
| ex.entry.point     | sys.ex.audit         |                      |
| ex.router.main     | q.type1        priority |
+---------+-----------------------+-----------+----------------------------------------------------------------------+--------------+----------+
| vhMon01 | unroutedMessagePolicy | exchanges | {"alternate-exchange": "sys.ex.unrouted"}          | type1                | | ex^ex.router.main* | 0    | q.type2   |
| vhMon01 | messageTimeoutPolicy  | queues    | type2       {"message-ttl": 30000, "dead-letter-exchange": "sys.ex.dead.letter"} | ^q.*         | |1 sys.ex.audit       |
sys.q.audit.01       |                      |
| sys.ex.dead.letter | sys.q.dead.letter.01 |                      |
| sys.ex.unrouted    | sys.q.unrouted.01    |                      |
++---------+-----------------------+-----------+---------------------------------------------------------+--------------+--------+----------+------------+

List the RabbitMQ users 

...

Code Block
titleTo show the rabbitmq users' permissions
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD list permissions
+---------+-----------+------+--------+-------+
|  vhost  | configure | read |  user  | write |
+---------+-----------+------+--------+-------+
| /       | .*        | .*   | rabbit | .*    |
| vhMon01 | .*        | .*   | rabbit | .*    |
+---------+-----------+------+--------+-------+

Sending a simple message to an

...

Exchange in a vhost

Code Block
titleSending a simple message to an exchange in a vhost
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST publish routing_key="type1" exchange="ex.topic.01" payload="type1: test message"

Sending a JSON File to an

...

Exchange in a vhost

In the example here, the file 'message01.json' contains json. It seems odd but the rabbitmqadmin command doesn't support sending files.

Code Block
titleSending a JSON file as a message to exchange in a vhost
JSON=$(cat message01.json);rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST publish exchange="ex.entry.point" properties='{"content_type":"application/json"}' routing_key="type1" payload="$JSON"(cat message01.json);rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST publish exchange="ex.entry.point" properties='{"content_type":"application/json"}' routing_key="type1" payload="$JSON"

Look at a single message on a Queue

This is the similar to the command for consuming a single messages but here the default value for 'ackmode' is 'ack_requeue_true' 

Code Block
titleLook at a single message on a Queue
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST get queue=queue1
+-------------+----------+---------------+-------------+---------------+------------------+-------------+
| routing_key | exchange | message_count |   payload   | payload_bytes | payload_encoding | redelivered |
+-------------+----------+---------------+-------------+---------------+------------------+-------------+
| queue1      |          | 3             | message one | 11            | string           | True        |
+-------------+----------+---------------+-------------+---------------+------------------+-------------+

Look at multiple messages on a Queue

This is the similar to the command for consuming messages but here the default value for 'ackmode' is 'ack_requeue_true' 

Code Block
titleLook at multiple messages on a Queue
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST get queue=queue1 count=3
+-------------+----------+---------------+---------------+---------------+------------------+-------------+
| routing_key | exchange | message_count |    payload    | payload_bytes | payload_encoding | redelivered |
+-------------+----------+---------------+---------------+---------------+------------------+-------------+
| queue1      |          | 3             | message one   | 11            | string           | True        |
| queue1      |          | 2             | message two   | 11            | string           | True        |
| queue1      |          | 1             | message three | 13            | string           | True        |
+-------------+----------+---------------+---------------+---------------+------------------+-------------+

Consume a single message from a Queue

This is similar to looking at messages except ackmode=ack_requeue_false

Code Block
titleConsume a single message from a Queue
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST get ackmode=ack_requeue_false queue=queue1
+-------------+----------+---------------+-------------+---------------+------------------+-------------+
| routing_key | exchange | message_count |   payload   | payload_bytes | payload_encoding | redelivered |
+-------------+----------+---------------+-------------+---------------+------------------+-------------+
| queue1      |          | 2             | message one | 11            | string           | False       |
+-------------+----------+---------------+-------------+---------------+------------------+-------------+

Consume multiple messages from a Queue

This is similar to looking at messages except ackmode=ack_requeue_false. Notice that we requested 3 messages from the Queue but only 2 were available.

Code Block
titleConsume multiple messages from a Queue
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST get queue=queue1 count=3 ackmode=ack_requeue_false
+-------------+----------+---------------+---------------+---------------+------------------+-------------+
| routing_key | exchange | message_count |    payload    | payload_bytes | payload_encoding | redelivered |
+-------------+----------+---------------+---------------+---------------+------------------+-------------+
| queue1      |          | 1             | message two   | 11            | string           | False       |
| queue1      |          | 0             | message three | 13            | string           | False       |
+-------------+----------+---------------+---------------+---------------+------------------+-------------+