Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.

...

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 --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

...

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

The following resources belong to a vhost 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 - limits 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 Resources

Using Rabbitmqadmin

...

Command Line 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 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 rabbit RabbitMQ configuration by hand. You 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 Rabbit RabbitMQ Configuration for just for that vhost.

...

RabbitMQ Configuration Files

A rabbitmqadmin config RabbitMQ config file either be associated with a single vhost or all vhosts. If you export a rabbitmqadmin file RabbitMQ configuration 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 a RabbitMQ configuration file for ALL vhosts - then it  the exported file will contain all the users, all the vhosts and all the permissions linking users to vhosts too.

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

When you import a rabbit config RabbitMQ configutation 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 any messages too )
  2. declare (create) the vhost - it will be empty - (expect for the standard amq queues/exchanges)
  3. import the config into the vhost

...

NameDescription
RBT_USERrabbit username
RBT_PASSWDrabbit password
VHOSTthe vhost being used

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

...

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 list vhosts
 declare vhost name=vhMon01
vhost declared

List all vhosts

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

...

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 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 export rabbit_config_for_vhost_exp.json
Exported definitions for localhost to "rabbit_config_for_vhost_exp.json"

...

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

...

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

...

Code Block
titleTo show exchanges of a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list queuesexchanges
+----------------------+----------+
|        name name       |  type | messages |
+----------------------+----------+
| q.type1              | 0     | direct  |
| q.type2amq.direct         | direct  |
| amq.fanout   | 0     | fanout  |
| sys.q.audit.01amq.headers        | 0headers |
| amq.match     | | sys.q.dead.letter.01 | 0    | headers |
| amq.rabbitmq.trace | topic   |
| amq.topic          | topic   |
| ex.entry.point     | fanout  |
| sysex.q.unrouted.01 router.main     | topic   |
0| sys.ex.audit       | +-fanout  |
| sys.ex.dead.letter | fanout  |
| sys.ex.unrouted    | fanout  |
+---------------------+----------+

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 exchanges queues of a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list exchangesqueues
+----------------------+----------+
|         name         |  type messages  |
+----------------------+----------+
| q.type1              | 0     | direct  |
| amqq.directtype2          | direct  | | amq.fanout 0        |
fanout  | | amq.headers sys.q.audit.01       | headers |
| amq.match0        |
| sys.q.dead.letter.01 | headers0 | | amq.rabbitmq.trace | topic   |
| amq.topicsys.q.unrouted.01    | 0     | topic   |
| ex.entry.point     | fanout  |
| ex.router.main     | topic   |
| sys.ex.audit       | fanout  |
| sys.ex.dead.letter | fanout  |
| sys.ex.unrouted    | fanout  |
+----------------------+----------+

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
+--------------------+----------------------+----------------------+
|       source       |     destination      |     routing_key      |
+--------------------+------------+

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  |   +
|                    | q.type1              | q.type1             name |
|        | apply-to  |         | q.type2              | q.type2     definition         |
|                    | sys.q.audit.01   pattern    | priority |
+---------+-----------------------+-----------+----------------------------------------------------------------------+--------------+----------+
| vhMon01 | unroutedMessagePolicy | exchanges | {"alternate-exchange": "sys.ex.unrouted"} 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| ex.router.* | 0entry.point     | sys.ex.audit         |
| vhMon01 | messageTimeoutPolicy  | queues                    | {"message-ttl": 30000, "dead-letter-exchange": "sys.ex.dead.letter"} | ^q.* |
| ex.router.main     | q.type1              | 1type1         |
+---------+-----------------------+-----------+----------------------------------------------------------------------+--------------+----------+

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.type2              | type2                |
| sys.ex.audit       | sys.q.audit.01       |                      |
| sys.ex.dead.letter | sys.q.dead.letter.01 |                      |
| sys.ex.unrouted    | sys.q.unrouted.01    |                      |
+--------------------+----------------------+----------------------+
|       source       |     destination      |     routing_key      |
+

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          | q.type1          apply-to    | q.type1              | |                    | q.type2definition               | q.type2              | |             pattern       | 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.mainpriority |
+---------+-----------------------+-----------+----------------------------------------------------------------------+--------------+----------+
| vhMon01 | unroutedMessagePolicy | exchanges | {"alternate-exchange": "sys.ex.unrouted"}       |                      | | ex^ex.entry.point    router.* | sys.ex.audit0        |
| vhMon01 | messageTimeoutPolicy  | queues    | {"message-ttl": 30000, "dead-letter-exchange":         |
| ex.router.main     | q.type1     "sys.ex.dead.letter"} | ^q.*         | type1        1        |
| ex.router.main     | q.type2              | type2                |
| 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 

The list of users is not vhost specific.

Code Block
firstlineTo show the rabbitmq users
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD list users
+--------+--------------------------------+--------------------+-----------------------+-------+---------------+

List the RabbitMQ users 

The list of users is not vhost specific.

Code Block
firstlineTo show the rabbitmq users
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD list users
+--
|  name  |       hashing_algorithm        |                  password_hash                   |     tags      |
+--------+--------------------------------+--------------------------------------------------+---------------+
|  name rabbit |       rabbit_password_hashing_algorithmsha256 | F1Aa/9adwlzfjHBLNnGF2yHPDMMSJD8h6fuhl+XJ21YbxUCR |  administrator   |                  password_hash                   |     tags      |
+--------+|
+--------+----------------------------------+--------------------------------------------------+---------------+
| rabbit | rabbit_password_hashing_sha256 | F1Aa/9adwlzfjHBLNnGF2yHPDMMSJD8h6fuhl+XJ21YbxUCR | administrator |

List the Permissions linking Users with Vhosts

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 | .*    |
+--------------+

List the Permissions linking Users with Vhosts

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"


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
+-------------+----------+-+------+--------+----------+

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"---+---------------+------------------+-------------+
| 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       |
+-------------+----------+---------------+---------------+---------------+------------------+-------------+