gpt4 book ai didi

python - 使用 Pika 客户端轮询 RabbitMQ 消息

转载 作者:太空宇宙 更新时间:2023-11-04 01:29:15 25 4
gpt4 key购买 nike

我想在 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

关于python - 使用 Pika 客户端轮询 RabbitMQ 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15138976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com