When you export the metadata of a RabbitMQ cluster, you can export all vhosts or a specific vhost. However, you are unable to directly export only some of the vhosts. To export some of the vhosts, you can export all vhosts and delete the vhosts that you do not need from the exported metadata file.

Prerequisites

The RabbitMQ management plug-in is enabled. You can use the RabbitMQ console or HTTP API to export the metadata of RabbitMQ clusters only after the plug-in is enabled. For more information, see Enable the RabbitMQ management plug-in.

Background information

A RabbitMQ cluster that has six vhosts is used as an example in this topic. The vhosts are hello1, hello_amqp, helloAMQP, example2test, example3test, and /. The following four vhosts need to be exported: hello1, hello_amqp, helloAMQP, and example2test.

Export some vhosts

  1. Use one of the following methods to export the metadata of the RabbitMQ cluster. The exported metadata file contains all vhosts of the cluster.
    • Open source RabbitMQ console
      1. Visit the RabbitMQ logon page from a browser.

        The URL is http://<RabbitMQ IP address>:15672/.

      2. On the RabbitMQ logon page, enter your username in the Username field and your password in the Password field, and click Login.
      3. On the Overview tab, expand Import/export definitions. Select All from the Virtual host drop-down list in the Export section. Then, click Download broker definitions.
      4. In the Save As dialog box, select the path where you want to save the metadata file of the RabbitMQ cluster and click Save.
    • RabbitMQ HTTP API
      1. Open the terminal.
      2. Run the following command to export the metadata file of the RabbitMQ cluster:
        wget --user <RabbitMQ account> --password <RabbitMQ password> http://<RabbitMQ IP address>:15672/api/definitions -O <Path of the metadata file>
    vhosts list in the exported metadata file:
    {
        "vhosts":[
            {
                "name":"hello1"
            },
            {
                "name":"hello_amqp"
            },
            {
                "name":"helloAMQP"
            },
            {
                "name":"example2test"
            },
            {
                "name":"example3test"
            },
            {
                "name":"/"
            }
        ]
    }
  2. Delete the example3test and / vhosts from the vhosts list in the exported metadata file.
    Note After you delete a vhost from the vhosts list, all exchanges, queues, and bindings under the vhost become invalid. When you import the metadata to a Message Queue for RabbitMQ instance, the exchanges, queues, and bindings under the vhost are automatically ignored.
    vhosts list in the exported metadata file after deletion:
    {
        "vhosts":[
            {
                "name":"hello1"
            },
            {
                "name":"hello_amqp"
            },
            {
                "name":"helloAMQP"
            },
            {
                "name":"example2test"
            }
        ]
    }