RabbitMQ - Create Virtual Host (vhost) using the REST API (curl)

This assumes you have created a RabbitMQ user with the administrator tag.

Refer to the RabbitMQ REST API documentation.

The curl command with the --user option can be used to make an API connection to RabbitMQ. In this example, John Doe will make a connection to the RabbitMQ server listening on port 15671 and create a virtual host named "foo".

curl 
--request PUT
--user john.doe:itsasecret
--header 'content-type: application/json'
--url http://hostname:15671/api/vhosts/foo
--write-out "%{http_code}"

 

Optionally, the virtual host can be given a description. It is noteworthy that the description will not be shown in the RabbitMQ web browser GUI, or when using the rabbitmqctl command. However, when listing virtual hosts using the REST API, the description will be included in the output.

curl 
--request PUT
--user john.doe:itsasecret
--header 'content-type: application/json'
--url http://hostname:15671/api/vhosts/foo
--data '{ "description": "example description" }'
--write-out "%{http_code}"

 

No output will be returned, regardless if the virtual host is or is not created. For this reason, the -w or --write-out option is included to get the return code of the curl command.




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter c0269 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |