我想在 Python 中创建一个 RabbitMQ 接收器/消费者,但我不确定如何检查消息。我正在尝试在我自己的循环中执行此操作,而不是使用 pika 中的回调。
如果我理解,在 Java 客户端中,我可以使用 getBasic() 来检查是否有任何消息可用而不会阻塞。我不介意在收到消息时阻塞,但我不想在有消息之前阻塞。
我没有找到任何明确的例子,也没有弄清楚鼠兔中的相应调用。
请您参考如下方法:
如果您想同步进行,则需要查看 pika BlockingConnection
The BlockingConnection creates a layer on top of Pika’s asynchronous core providng methods that will block until their expected response has returned. Due to the asynchronous nature of the Basic.Deliver and Basic.Return calls from RabbitMQ to your application, you are still required to implement continuation-passing style asynchronous methods if you’d like to receive messages from RabbitMQ using basic_consume or if you want to be notified of a delivery failure when using basic_publish.
更多信息和例子在这里
https://pika.readthedocs.org/en/0.9.12/connecting.html#blockingconnection
