Get Virtual Hosts in RabbitMQ

Get Virtual Hosts in RabbitMQ

Virtual hosts in RabbitMQ provide a way to separate different environments or applications within a single RabbitMQ instance. Each virtual host acts as a namespace for exchanges, queues, and bindings. Knowing how to list virtual hosts can be helpful for monitoring, debugging, or managing your RabbitMQ setup. This tutorial explains how to get virtual hosts in RabbitMQ.

1. CLI

RabbitMQ provides a built-in command line tool called rabbitmqctl, which allows you to manage and inspect various aspects of the RabbitMQ server.

To list virtual hosts, use the following command:

sudo rabbitmqctl -s list_vhosts

Example output:

/
testing

This output shows two virtual hosts: / (the default virtual host) and testing.

2. HTTP API

RabbitMQ also provides an HTTP API that allows you to query and manage the server programmatically. You can retrieve the list of virtual hosts using a curl command.

Run the following command:

curl -u guest:guest http://localhost:15672/api/vhosts

The part of the output:

[
  {
    ...
    "name": "/",
    "tags": [],
    "tracing": false
  },
  {
    ...
    "name": "testing",
    "tags": [],
    "tracing": false
  }
]

This JSON response contains an array of objects, each representing a virtual host.

Leave a Comment

Cancel reply

Your email address will not be published.