以下代码是我用来计算消费者数量的代码:
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(host='IP ADDRESS'))
channel = connection.channel()
this=channel.queue_declare(queue="Queue_name",passive=True)
print this.method.consumer_count
现在我获得的计数是活跃消费者的数量。但是,当消费者从队列中消费时,此计数打印为零。现在我需要从队列中消费的消费者总数。这样就出现了 RabbitMQ 管理 (作为消费者:0 活跃 共 25 个)
有没有办法在队列中有消息的情况下获取从队列中消费的消费者总数?
提前致谢
请您参考如下方法:
以下是对这个问题的回答。但是,它使用 HTTP API 而不是 pika。
import subprocess
import os
import json
#Execute in command line
def execute_command(command):
proc = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE)
script_response = proc.stdout.read().split('\n')
resp=json.loads(script_response[7])
print resp[0]['name']
print resp[0]['consumers']
######### MAIN #########
if __name__ == '__main__':
execute_command('curl -i -u guest:guest http://*IP ADDRESS*:15672/api/queues/')
请引用:http://hg.rabbitmq.com/rabbitmq-management/raw-file/3646dee55e02/priv/www-api/help.html
