LinuxCommandLibrary

rabbitmqctl-vhosts

Manage RabbitMQ virtual hosts

TLDR

List all virtual hosts

$ rabbitmqctl list_vhosts
copy

Add a new virtual host
$ rabbitmqctl add_vhost [vhost_name]
copy

Delete a virtual host
$ rabbitmqctl delete_vhost [vhost_name]
copy

Set permissions for a user on a specific virtual host
$ rabbitmqctl set_permissions [[-p|--vhost]] [vhost_name] [username] [read] [write] [configure]
copy

Clear permissions for a user on a specific virtual host
$ rabbitmqctl clear_permissions [[-p|--vhost]] [vhost_name] [username]
copy

SYNOPSIS

rabbitmqctl [--node node] [--longnames | --shortnames] [--quiet] [--timeout timeout] [--detached] vhosts

PARAMETERS

--node node
    Specifies the Erlang node name of the RabbitMQ broker to connect to. Defaults to rabbit@ followed by the hostname.

--longnames
    Forces the use of long node names (e.g., rabbit@hostname.domain) for connection.

--shortnames
    Forces the use of short node names (e.g., rabbit@hostname) for connection.

--quiet
    Suppresses informative messages, displaying only errors or the requested output.

--timeout timeout
    Sets a timeout in seconds for the command execution. If the command does not complete within this time, it will abort.

--detached
    Runs the command in a detached mode, allowing the client to exit while the command continues execution on the server. Less common for this listing command.

DESCRIPTION

The rabbitmqctl vhosts command is a fundamental part of the RabbitMQ command-line management tool, rabbitmqctl. Its primary function is to list all existing virtual hosts (vhosts) configured on a RabbitMQ broker or cluster. Virtual hosts are essential for providing logical separation and isolation within a single RabbitMQ instance. Each vhost acts as an independent mini-RabbitMQ broker, possessing its own set of users, permissions, exchanges, queues, and bindings. This segregation prevents name clashes and enhances security and multi-tenancy.

While rabbitmqctl vhosts specifically provides a simple list of vhost names, the broader rabbitmqctl utility offers extensive capabilities for managing them, including creating (add_vhost), deleting (delete_vhost), and managing user permissions (set_permissions). Utilizing virtual hosts effectively is crucial for organizing resources, ensuring security, and implementing multi-application or multi-tenant architectures in RabbitMQ deployments. This command serves as a quick inspection tool for administrators to see which vhosts are currently active.

CAVEATS

  • Permissions: The user running rabbitmqctl must have appropriate operating system permissions to connect to the RabbitMQ Erlang node. This often means running as the rabbitmq user or with sudo privileges.
  • Node Name Resolution: Ensure that the hostname used in the node name (e.g., rabbit@hostname) is correctly resolvable from where rabbitmqctl is executed. Incorrect hostnames or DNS issues can prevent successful connection.
  • Cluster State: In a clustered RabbitMQ environment, this command connects to a single node. While virtual hosts are globally synchronized across the cluster, local node issues could affect connectivity or the perceived state.
  • Output Limitations: rabbitmqctl vhosts only lists names. For more detailed information about virtual hosts, such as description or runtime properties, consider using rabbitmqctl list_vhosts with specific columns.

VIRTUAL HOST IMPORTANCE

Virtual hosts are critical for achieving multi-tenancy, enhancing security, and isolating resources within a RabbitMQ cluster. They allow different applications or departments to share the same broker without their messaging entities (queues, exchanges) interfering with each other.

DEFAULT VIRTUAL HOST

RabbitMQ automatically creates a default virtual host named / (slash) upon installation. While convenient for initial setup and testing, it is strongly recommended to create dedicated virtual hosts for production applications to ensure proper isolation and management.

COMPARISON WITH <I>LIST_VHOSTS</I>

While rabbitmqctl vhosts provides a simple list of names, rabbitmqctl list_vhosts offers more granular control. It allows administrators to specify which columns of information to display (e.g., name, description, policy), making it more suitable for detailed reporting or scripting purposes.

HISTORY

The rabbitmqctl command-line tool, including its vhosts subcommand, has been a core component of RabbitMQ since its early versions. RabbitMQ, initially released in 2007 by Rabbit Technologies (later acquired by VMware, Pivotal, and now part of Broadcom), was designed with a focus on robust message brokering and flexible management. The rabbitmqctl utility emerged as the primary interface for managing cluster operations, user and permission configurations, and virtual host settings. The concept of virtual hosts has been fundamental to RabbitMQ's architecture, enabling logical separation of messaging environments. As RabbitMQ evolved, rabbitmqctl has seen continuous enhancements in its functionality and usability, though its essential role in virtual host management has remained consistent.

SEE ALSO

rabbitmqctl(8), rabbitmqctl add_vhost(8), rabbitmqctl delete_vhost(8), rabbitmqctl set_permissions(8), rabbitmqctl list_vhosts(8)

Copied to clipboard