How can I list or discover queues on a RabbitMQ exchange using python?

前端 未结 8 2293
长发绾君心
长发绾君心 2020-12-09 01:29

I need to have a python client that can discover queues on a restarted RabbitMQ server exchange, and then start up a clients to resume consuming messages from each queue. Ho

8条回答
  •  臣服心动
    2020-12-09 02:15

    You can add plugin rabbitmq_management

    sudo /usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management
    sudo service rabbitmq-server restart
    

    Then use rest-api

    import requests
    
    def rest_queue_list(user='guest', password='guest', host='localhost', port=15672, virtual_host=None):
        url = 'http://%s:%s/api/queues/%s' % (host, port, virtual_host or '')
        response = requests.get(url, auth=(user, password))
        queues = [q['name'] for q in response.json()]
        return queues
    

    I'm using requests library in this example, but it is not significantly.

    Also I found library that do it for us - pyrabbit

    from pyrabbit.api import Client
    cl = Client('localhost:15672', 'guest', 'guest')
    queues = [q['name'] for q in cl.get_queues()]
    

提交回复
热议问题