简体   繁体   English

RabbitMQ - Python/Pika 如何知道队列是否为空?

[英]RabbitMQ - Python/Pika How to know if queue is empty?

My idea is also described here if I express myself incorrectly ( Send images with their names in one message - RabbitMQ (Python 3.X) )如果我表达不正确,我的想法也会在这里描述( 在一条消息中发送带有名称的图像 - RabbitMQ (Python 3.X)

I currently have a problem with RabbitMQ --->我目前在使用 RabbitMQ 时遇到问题 --->

I made a working queue on which several consumers work at the same time, it is a containerized image processing that gives a str output with the requested information.我制作了一个工作队列,多个消费者同时在其上工作,它是一个容器化的图像处理,可提供带有请求信息的 str 输出。

The results must be sent on another queue when the processing is finished, but how do I know if the queue containing the images is empty and there is no more work to do?处理完成后,结果必须发送到另一个队列,但我如何知道包含图像的队列是否为空并且没有更多工作要做? I would like to know if a command like "if the queue is empty, then send the results..." to say it roughly.我想知道像“如果队列为空,则发送结果......”这样的命令是否可以粗略地说出来。

Thank you for your time, have a good day.谢谢你的时间,祝你有美好的一天。

You can do a passive declare of the queue to get the count of messages, but that may not be reliable as the count returned does not include messages in the "unacked" state.您可以对队列进行被动声明以获取消息计数,但这可能不可靠,因为返回的计数不包括处于“未确认”状态的消息。 You could query the queue's counts via the HTTP API.您可以通过 HTTP API 查询队列的计数。

Or, whatever application publishes the images could send a "no more images" message to indicate no more work to do.或者,任何发布图像的应用程序都可以发送“没有更多图像”消息以指示没有更多工作要做。 The consumer that receives that message could then query the HTTP API to confirm that no messages are in the Ready or Unacked state, then send the results to the next queue.接收该消息的消费者然后可以查询 HTTP API 以确认没有消息处于就绪或未确认状态,然后将结果发送到下一个队列。


NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.注意: RabbitMQ 团队会监控rabbitmq-users邮件列表,并且只是偶尔在 StackOverflow 上回答问题。

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

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