Create vHost on Windows RabbitMQ node using command line
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
RabbitMQ is a popular open-source message-broker software that facilitates the efficient handling of messages between different components of an application. In scenarios involving multiple services, virtual hosts (vHosts) in RabbitMQ play a pivotal role in segmenting the environment to provide a way to isolate applications.
What is a vHost?
A virtual host (vHost) in RabbitMQ acts like a mini RabbitMQ server inside a physical RabbitMQ instance. It provides logical grouping and isolation, meaning that exchanges, queues, and bindings you create on one vHost are completely separate from others.
Each vHost has its own set of permissions, and users can be given access rights specific to a vHost. This approach allows for multi-tenancy and better security management within the same RabbitMQ instance.
Why Use vHosts?
- Isolation: Ensures that applications do not interfere with each other's messages, queues, and configurations.
- Security: Provides a means to control access to different broker resources securely.
- Organization: Helps in logically organizing and managing different environments like testing, development, and production within the same RabbitMQ server.
Creating vHosts on Windows using RabbitMQ Command Line
Here’s a step-by-step guide to creating a vHost on a RabbitMQ node running on a Windows system using the RabbitMQ command-line tools.
Prerequisites
- Ensure RabbitMQ is installed and running on your Windows machine.
- Confirm that the RabbitMQ CLI tools are correctly set up and accessible in your system’s path.
Step-by-step Process
- Open Command Prompt: Start by opening the Command Prompt as an Administrator.
- Navigate to RabbitMQ sbin directory: Depending on your RabbitMQ installation path, you might need to change the directory to where RabbitMQ’s command-line tools are located, typically within the
sbindirectory of RabbitMQ’s installation folder.
- Create a New vHost: Use the
rabbitmqctlcommand to add a new virtual host.
Replace myNewVHost with the desired name for your virtual host.
- Verify Creation: To ensure the vHost was created successfully, list all available vHosts.
- Set Permissions: After creating the vHost, you’ll need to set permissions for users. By default, no user has permissions on the new vHost, so you will need to explicitly set these.
Here, myuser is the username, and the three .* expressions set configure, write, and read permissions respectively. This setup allows myuser complete access to the vHost.
Key Points Summary
| Operation | Command Example | Description |
| Navigate to sbin | cd C:\Program Files\RabbitMQ Server\rabbitmq_server-3.9.8\sbin | Change directory to RabbitMQ CLI tools |
| Create vHost | rabbitmqctl add_vhost myNewVHost | Command to create a new virtual host |
| List vHosts | rabbitmqctl list_vhosts | Command to list all virtual hosts |
| Set Permissions | rabbitmqctl set_permissions -p myNewVHost myuser ".*" ".*" ".*" | Set permissions for a user on vHost |
Additional Tips
- Naming Conventions: Choose clear and consistent naming conventions for vHosts to avoid confusion, especially in environments with many vHosts.
- Managing Users: Regularly review and manage user permissions to ensure that access is secure and appropriate to the user’s role.
- Backup and Monitoring: Implement regular backups and monitoring for your RabbitMQ environment, including all vHost configurations.
By following this guide, you can effectively create and manage virtual hosts in RabbitMQ on a Windows environment, optimizing the security and efficiency of your message-based applications.

