Search code examples
amqppikarabbitmqctlpython-pika

check and create amqp virtual host (vhost) in python (pika)


I am new to pika (https://github.com/pika/pika). I wonder whether there are APIs to check whether one virtual host exists or not, and whether there are APIs to create virtual host. I know that vhost can be created by rabbitmqctl, but I did not find them in pika... Did I miss anything?


Solution

  • We can use the rabbitmq web management plugin (https://www.rabbitmq.com/management.html), which provide REST APIs. What we need to do is to write program to do PUT and GET.

    There are some good examples:

    (1) a good client: pyrabbit, https://github.com/bkjones/pyrabbit/blob/master/pyrabbit/api.py;

    (2) some code based on requests. https://github.com/numenta/numenta-apps/blob/1ff572a21a5c27fd290822e572ce33f42e1ee19e/nta.utils/nta/utils/test_utils/amqp_test_utils.py#L145-L160

    (3) good examples based on urllib2: https://github.com/jasonmcintosh/rabbitmq-zabbix/blob/master/scripts/rabbitmq/api.py