Skip to main content

Using Management CLI

1. Using rabbitmqctl

The rabbitmqctl command-line tool is a powerful utility for managing and monitoring RabbitMQ nodes. It allows administrators to perform various administrative tasks such as starting/stopping nodes, managing users, permissions, and queues.

Command Description Example
eval Evaluates Erlang expressions on the node rabbitmqctl eval "rabbit_queue_index:info()"
status Displays the status of the RabbitMQ node rabbitmqctl status
list_queues Lists all queues on the node rabbitmqctl list_queues name messages consumers
list_exchanges Lists all exchanges on the node rabbitmqctl list_exchanges name type
list_bindings Lists all bindings between exchanges and queues rabbitmqctl list_bindings source exchange destination queue
list_users Lists all users on the node rabbitmqctl list_users
list_vhosts Lists all virtual hosts on the node rabbitmqctl list_vhosts
start_app Starts the RabbitMQ application rabbitmqctl start_app
stop_app Stops the RabbitMQ application rabbitmqctl stop_app
force_shutdown Forcefully shuts down the RabbitMQ application rabbitmqctl force_shutdown

Example: Listing Queues with Details

rabbitmqctl list_queues name messages consumers durable auto_delete

Example: Listing Users and Their Permissions

rabbitmqctl list_users name tags permissions
Note: The rabbitmqctl command must be run from the RabbitMQ server's command line or via SSH access to the node.
Warning: Be cautious when using commands like force_shutdown, as they can cause data loss or inconsistencies if not used properly.

2. Listing Queues

Option Values Description
--host localhost Hostname of the RabbitMQ node
--port 15672 Management plugin port
--user guest Username for authentication
--password guest Password for authentication

Example: List all queues on a RabbitMQ instance

rabbitmqctl list_queues -p /

Example: List queues with specific name pattern

rabbitmqctl list_queues -p / name

Example: List queues with detailed information

rabbitmqctl list_queues -p / name messages consumers
Note: The -p flag specifies the virtual host. By default, it uses the root (/) virtual host.

3. Listing Exchanges

Property Description Default Value
exchange.name Name of the exchange None
exchange.type Type of the exchange (direct, fanout, topic, headers) direct
exchange.durable Whether the exchange survives broker restarts true
exchange.auto_delete Whether the exchange is deleted when no longer used false
exchange.internal Whether the exchange is internal (used by the broker) false

Example: Listing Exchanges via CLI

rabbitmqctl list_exchanges

Example: Listing Exchanges with Details

rabbitmqctl list_exchanges name type durable auto_delete internal
Note: The rabbitmqctl command must be run on the RabbitMQ node where the management plugin is enabled.

4. Listing Bindings

Property Description Default Value Notes
binding.source Source exchange name None Required field
binding.destination Destination queue or exchange name None Required field
binding.routing_key Routing key used for binding None Optional field
binding.destination_type Type of destination (queue or exchange) queue Can be 'queue' or 'exchange'

Example: Listing bindings using CLI

rabbitmqctl list_bindings

Example: Listing bindings with specific source

rabbitmqctl list_bindings --from exchange_name

Example: Listing bindings with specific destination

rabbitmqctl list_bindings --to queue_name

5. Listing Connections

Command Description Example
rabbitmqctl list_connections List all active connections to the broker rabbitmqctl list_connections
rabbitmqctl list_connections -q Quiet mode, outputs only connection IDs rabbitmqctl list_connections -q
rabbitmqctl list_connections --offline Include offline connections in the listing rabbitmqctl list_connections --offline
Note: The output includes connection details such as user, host, port, and idle time.

6. Listing Channels

Command Description Options
rabbitmqctl list_channels Lists all channels in the RabbitMQ instance -p VHOST - Specify virtual host
--offline - Include offline channels

Example: Listing Channels

rabbitmqctl list_channels

Example: Listing Channels in Specific Virtual Host

rabbitmqctl list_channels -p /my_vhost

7. Listing Consumers

Option Values Notes
--host localhost Hostname of the RabbitMQ server
--port 15672 Management HTTP API port
--user guest Username for authentication
--password guest Password for authentication

Example: Listing Consumers

rabbitmqctl list_consumers
Note: Requires rabbitmqctl to be run on the RabbitMQ node.

8. Using rabbitmqadmin

The rabbitmqadmin command-line tool is a powerful utility for managing RabbitMQ instances. It provides a convenient way to interact with the management HTTP API without requiring custom scripts or extensive configuration.

Command Description Example
list queues List all queues in the default vhost rabbitmqadmin list queues
list exchanges List all exchanges in the default vhost rabbitmqadmin list exchanges
declare queue Create a new queue rabbitmqadmin declare queue name=my_queue durable=true
declare exchange Create a new exchange rabbitmqadmin declare exchange name=my_exchange type=direct
publish Publish a message to an exchange rabbitmqadmin publish exchange=my_exchange routing_key=my_key payload='{"message": "Hello"}'

NEW As of RabbitMQ 3.12, rabbitmqadmin supports JSON output format via the --format=json option.

Example: Listing Queues with Details

rabbitmqadmin list queues name messages consumers state

Example: Creating a Queue with Arguments

rabbitmqadmin declare queue name=ttl_queue arguments='{"x-message-ttl": 60000}'
Note: Ensure that the rabbitmqadmin tool is in your PATH or use its full path. The tool requires access to the RabbitMQ management plugin and appropriate permissions to perform actions.

9. Declaring Resources

Resource Type Declaration Syntax Description Notes
exchange exchange.declare Declares an exchange Used to define how messages are routed
queue queue.declare Declares a queue Stores messages until consumed
binding queue.bind Binds a queue to an exchange Defines routing rules between exchanges and queues
vhost vhost.create Creates a virtual host Isolates resources in different environments

Example: Declaring an Exchange

rabbitmqctl declare_exchange my_exchange \
  --type direct \
  --durable true \
  --auto-delete false

Example: Declaring a Queue

rabbitmqctl declare_queue my_queue \
  --durable true \
  --auto-delete false \
  --arguments '{"x-message-ttl":3600000}'

Example: Binding a Queue to an Exchange

rabbitmqctl bind_queue my_queue \
  --exchange my_exchange \
  --routing-key my_key

10. Purging and Deleting

Operation Description CLI Command Notes
Purge Queue Remove all messages from a queue rabbitmqadmin purge queue=name Messages are permanently deleted, cannot be recovered
Delete Queue Remove a queue and all its messages rabbitmqadmin delete queue=name Queue must not be in use by consumers
Delete Exchange Remove an exchange and its bindings rabbitmqadmin delete exchange=name Exchange must not be in use by bindings or queues

Example: Purge a Queue

rabbitmqadmin purge queue=my_queue

Example: Delete a Queue

rabbitmqadmin delete queue=my_queue
Note: Purging a queue is faster than deleting and recreating it, especially for large queues.
Warning: Purging or deleting queues and exchanges is irreversible. Ensure you have backups or are certain about the action before proceeding.

11. Exporting Definitions

Use the rabbitmqctl command to export RabbitMQ definitions such as exchanges, queues, and bindings.

Example: Exporting Definitions

rabbitmqctl export_definitions /path/to/definitions.json
Option Values Description
--output file Specifies the output file path for the exported definitions
--format json Specifies the format of the exported definitions (default is JSON)
Note: The exported definitions can be used to restore the RabbitMQ configuration on another instance.
Warning: Ensure that the RabbitMQ service is running and accessible before exporting definitions.

12. Importing Definitions

Example: Importing Definitions from a File

rabbitmqctl import_definitions /path/to/definitions.json
Option Values Description
--input-file definitions.json Path to the JSON file containing definitions to import
--vhost /my-vhost Virtual host to import definitions into (optional)
--force true Overwrite existing definitions without confirmation (optional)
Note: The definitions file must be in the correct JSON format as exported by rabbitmqctl export_definitions.
Warning: Importing definitions will overwrite existing configurations in the specified virtual host.

Importing Definitions - Summary

  • Use rabbitmqctl import_definitions to restore RabbitMQ configuration from a JSON file.
  • Supports importing definitions into specific virtual hosts.
  • Use --force to bypass confirmation prompts during import.

Was this article helpful?