Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

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 'Management Plugin'. Not every RabbitMQ deployment will have the 'Management Plugin' installed.

Rabbit REST API

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 : 

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

curl_output_file.json

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

Rabbitmqadmin CLI tool

The 'rabbitmqadmin' cli tool can be downloadable from each rabbit server that has the 'Management Plugin' installed. It can be downloaded from 'http://<rabbit-server>:<rabbit-port>/cli/rabbitmqadmin' internally, it talks to the RabbitMQ installation using the Rabbit Rest API. The rabbitmqadmin tool uses 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 on another machine using --host and --port parameters. 

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

Rabbitmqctl CLI tool

The following is copied from this excellent stackoverflow answer

  • rabbitmqctl is native command line tool written in Erlang, in general, it is used inside the same server where RabbitMQ is running.

  • rabbitmqadmin is a Python interface for the HTTP management UI. You cannot use it if management UI plugin is not installed.

There is an overlap between the two tools, but there are a few features that you can use only with one of them.

With rabbitmqctl you can:

  • manage the rabbitmq clustuer, by adding/removing nodes.
  • reset the node
  • handle logs files rotation
  • stop the node

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 Resources

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:

NameDescription
RBT_USERrabbit username
RBT_PASSWDrabbit password
VHOSTthe vhost being used

Create a new vhost

Create a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD declare vhost name=vhMon01
vhost declared

List all vhosts

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

Delete a vhost

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

Delete a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD delete vhost name=vhMon01
vhost deleted

Import Rabbit Configuration File into a vhost

Import 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

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

Purge all messages on queues for a vhost

This is a single (but long) unix command line

Purge 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 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 a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list queues
+----------------------+----------+
|         name         | messages |
+----------------------+----------+
| q.type1              | 0        |
| q.type2              | 0        |
| sys.q.audit.01       | 0        |
| sys.q.dead.letter.01 | 0        |
| sys.q.unrouted.01    | 0        |
+----------------------+----------+

List the exchanges associated with a vhost

To show exchanges of a vhost
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list exchanges
+--------------------+---------+
|        name        |  type   |
+--------------------+---------+
|                    | direct  |
| amq.direct         | direct  |
| amq.fanout         | fanout  |
| amq.headers        | headers |
| amq.match          | headers |
| amq.rabbitmq.trace | topic   |
| amq.topic          | topic   |
| ex.entry.point     | fanout  |
| ex.router.main     | topic   |
| sys.ex.audit       | fanout  |
| sys.ex.dead.letter | fanout  |
| sys.ex.unrouted    | fanout  |
+--------------------+---------+

List the policies associated with a vhost

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

List the bindings associated with a vhost

To show bindings of a vhost
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD --vhost=$VHOST list bindings
+--------------------+----------------------+----------------------+
|       source       |     destination      |     routing_key      |
+--------------------+----------------------+----------------------+
|                    | q.type1              | q.type1              |
|                    | q.type2              | q.type2              |
|                    | 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.entry.point     | sys.ex.audit         |                      |
| ex.router.main     | q.type1              | type1                |
| 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.

Error rendering macro 'code': Invalid value specified for parameter 'firstline'
rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD list users
+--------+--------------------------------+--------------------------------------------------+---------------+
|  name  |       hashing_algorithm        |                  password_hash                   |     tags      |
+--------+--------------------------------+--------------------------------------------------+---------------+
| rabbit | rabbit_password_hashing_sha256 | F1Aa/9adwlzfjHBLNnGF2yHPDMMSJD8h6fuhl+XJ21YbxUCR | administrator |
+--------+--------------------------------+--------------------------------------------------+---------------+

List the Permissions linking Users with Vhosts

To show the rabbitmq users' permissions
$ rabbitmqadmin --user=$RBT_USER --password=$RBT_PASSWD list permissions
+---------+-----------+------+--------+-------+
|  vhost  | configure | read |  user  | write |
+---------+-----------+------+--------+-------+
| /       | .*        | .*   | rabbit | .*    |
| vhMon01 | .*        | .*   | rabbit | .*    |
+---------+-----------+------+--------+-------+
  • No labels