pika总是显示RabbitMQ队列大小为0

问题描述 投票:3回答:1

我正在尝试使用鼠标来获取RabbitMQ队列中的项目数。我有以下运行:

params = pika.ConnectionParameters(host='my.host.com', port=5672, credentials=pika.credentials.PlainCredentials('myuser', 'myauth'))
connection = pika.BlockingConnection(parameters=params)
channel = connection.channel()
response = channel.queue_declare(passive=True, queue='my-queue-name')
count = response.method.message_count
channel.close()
print response

当我运行它时,无论队列中有多少项,count始终为0。我可以看到rabbitmqctl中的项目,但我的脚本不会显示它们。我在这做错了什么?

python rabbitmq pika
1个回答
0
投票

回答可能为时已晚,但我只是遇到了几乎相同的问题。我需要在发布者的队列端进行一些限制,我决定定期检查队列大小以减慢处理速度。但是当我提起消费者的队列结束时,pika的queue_declare(..., passive=True).method.message_count开始报告零。经过一段时间的测试和浏览代码/样本后,我发现设置channel.basic_qos(prefetch_count=1)解决了这个问题。希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.