How to Use rabbitmqctl: Commands and Examples
Use
rabbitmqctl to manage RabbitMQ server from the command line. It lets you check server status, list users, manage queues, and control nodes by running commands like rabbitmqctl status or rabbitmqctl list_queues.Syntax
The basic syntax of rabbitmqctl is:
rabbitmqctl [command] [options]
Here, command is the action you want to perform, such as status, list_queues, or add_user. options are extra details needed for some commands, like usernames or queue names.
bash
rabbitmqctl [command] [options]
Example
This example shows how to check the RabbitMQ server status and list all queues with their message counts.
bash
rabbitmqctl status rabbitmqctl list_queues name messages
Output
Status of node rabbit@hostname ...
[{pid,12345},
{running_applications,[{rabbit,"RabbitMQ","3.11.10"},
{os_mon,"CPO CXC 138 46"},
{mnesia,"MNESIA CXC 138 12"}]},
{listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
{vm_memory_high_watermark,0.4},
{disk_free_limit,50000000},
{disk_free,123456789}]
queue1 10
queue2 0
queue3 5
Common Pitfalls
Common mistakes when using rabbitmqctl include:
- Running commands without proper permissions or as a non-root user, causing permission errors.
- Using
rabbitmqctlon a remote server without SSH or proper access. - Confusing
rabbitmqctlcommands withrabbitmqadmin, which is a different tool. - Not specifying the correct node name if multiple RabbitMQ nodes run on the same machine.
Always run rabbitmqctl on the server where RabbitMQ is installed and with sufficient privileges.
bash
## Wrong: Running without sudo (may fail) rabbitmqctl status ## Right: Running with sudo sudo rabbitmqctl status
Quick Reference
| Command | Description |
|---|---|
| rabbitmqctl status | Shows RabbitMQ server status and node info |
| rabbitmqctl list_queues | Lists all queues with details like message count |
| rabbitmqctl add_user | Creates a new RabbitMQ user |
| rabbitmqctl delete_user | Deletes an existing user |
| rabbitmqctl set_permissions -p | Sets user permissions on a virtual host |
| rabbitmqctl stop | Stops the RabbitMQ server node |
| rabbitmqctl reset | Resets the node (clears data, use with caution) |
Key Takeaways
Use
rabbitmqctl commands on the RabbitMQ server with proper permissions.Common commands include
status, list_queues, and user management commands.Always run
rabbitmqctl with sudo if permission errors occur.Do not confuse
rabbitmqctl with rabbitmqadmin, they serve different purposes.Check the node name if managing multiple RabbitMQ nodes on the same machine.