简体   繁体   English

Rabbitmq/Pika - 在 python 中获取给定队列的消费者列表

[英]Rabbitmq/Pika - get a consumer list of a given queue in python

I would like to find a way to get a list of the consumers that are connected to a given queue in rabbitmq in python.我想找到一种方法来获取在 python 中的rabbitmq 中连接到给定队列的消费者列表。 need a script that returns a list of the consumer that are connected to a queue(for me its devices) the ip and name.需要一个脚本来返回连接到队列(对我来说是它的设备)IP 和名称的消费者列表。

Thanks for the help!谢谢您的帮助!

connection = pika.BlockingConnection(parameters)
channel = connection.channel()
queue_state = channel.queue_declare(
    queue='some_Queue', passive=True,  durable=True)

I found a way to get the consumers count, but not the list of the consumer itself.. so still no solution:我找到了一种让消费者计数的方法,但不是消费者本身的列表..所以仍然没有解决方案:

consumers = queue_state.method.consumer_count
print(consumers)

Try to use the monotoring APIs:尝试使用监控 API:

import requests
from requests.auth import HTTPBasicAuth

api_queues = 'http://' + host_ip + ':' + api_port + '/api/queues/%2F/'+queue_name
res = requests.get(api_queues, auth=HTTPBasicAuth(login, password))
res_json = res.json()
# Number of consumers
number_of_consumers= len(res_json['consumer_details'])

Please not that '%2F' is used when the vhost is '/'.请注意,当虚拟主机为“/”时使用了“%2F”。

Regards问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM