Updated on 2023-05-05 GMT+08:00

Creating a Virtual Host

Scenario

Each virtual host serves as an independent RabbitMQ server. Virtual hosts provide logical separation of exchanges, queues, and bindings. Different applications run on different virtual hosts without interfering with each other. An instance can have multiple virtual hosts, and a virtual host can have multiple exchanges and queues. To connect a producer or consumer to a RabbitMQ instance, you must specify a virtual host. For details, see Virtual Hosts on the official RabbitMQ website.

Methods of creating a virtual host:

Method 1: Creating a Virtual Host on the Console

  1. Log in to the management console.
  2. In the upper left corner, click and select a region.

    Select the region where your RabbitMQ instance is.

  3. Click and choose Middleware > Distributed Message Service for RabbitMQ to open the console of DMS for RabbitMQ.
  4. Click an instance to go to the details page.
  5. In the navigation pane, choose Virtual Hosts.
  6. Click Create Virtual Host.
  7. Enter a virtual host name and click OK.

    After the creation is successful, the new virtual host is displayed in the virtual host list.

    Tracing indicates whether message tracing is enabled. If it is enabled, you can trace the message forwarding path.

    • The virtual host name cannot be modified once specified.
    • After an instance is created, a virtual host named / is automatically created.

Method 2: Creating a Virtual Host on the RabbitMQ Management UI

  1. Log in to the RabbitMQ management UI.
  2. On the top navigation bar, choose Admin.
  3. In the navigation tree on the right, choose Virtual Hosts.

    Figure 1 Virtual Hosts

  4. In the Add a new virtual host area, enter the virtual host name and click Add virtual host.

    Figure 2 Creating a virtual host (management UI)

    After the creation is successful, the new virtual host is displayed in the All virtual hosts area.

    Figure 3 Virtual host list (management UI)

Method 3: Creating a Virtual Host by Calling an API

  1. In Linux, connect to the RabbitMQ instance.
  2. Run the following command to create a virtual host:

    curl -i -X PUT http://${USERNAME}:${PASSWORD}@${HOST}:${PORT}/api/vhosts/${VHOST_NAME}

    Parameter description:

    • USERNAME: username set when the RabbitMQ instance was created. View the username in the Connection area on the instance details page.
    • PASSWORD: password set when the RabbitMQ instance was created. If you forget the password, reset it.
    • HOST: IP address of the management UI. View the management UI address in the Connection area on the instance details page.
    • PORT: port of the management UI. View the management UI port in the Connection area on the instance details page.
    • VHOST_NAME: name of the virtual host to be created.

    Example:

    curl -i -X PUT http://root:txxxt@192.168.1.3:15672/api/vhosts/vhost-demo

    If the creation is successful, the following information is displayed.

    Figure 4 Virtual host created successfully