如何在AMQP的python客户端中使用listen on basic.return
我想确保我的消息已传递到队列中。
为此,我将强制参数添加到 basic_publish 中。 如果我的消息未成功发送,我还应该做什么才能收到 basic.return
消息?
我无法使用 channel.wait()
监听 basic.return
,因为当我的消息成功传递时,wait()
函数永远挂起。 (没有超时) 另一方面。当我不调用 channel.wait()
时,channel.returned_messages
将保持为空,即使消息未传递。
我使用 py-amqplib 版本 0.6。
欢迎任何解决方案。
I'd like to make sure that my message was delivered to a queue.
To do so I'm adding the mandatory param to the basic_publish.
What else should I do to receive the basic.return
message if my message wasn't successfully delivered?
I can't use channel.wait()
to listen for the basic.return
because when my message is successfully delivered the wait()
function hangs forever. (There is no timeout)
On the other hand. When I don't call channel.wait()
the channel.returned_messages
will remain empty, even if the message isn't delivered.
I use py-amqplib
version 0.6.
Any solution is welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
目前这是不可能的,因为当消息在代理中删除时,
basic.return
是异步发送的。消息发送成功后,服务器不会报告任何数据。所以 pyAMQP 无法监听此类消息。
我读过一些关于这个问题的帖子。可能的解决方案是:
basic.return
消息。由于对 pyAMQP 和rabbitMQ 的支持水平总体来说相当低,因此我们决定根本不使用 amqp 代理。
It is currently impossible as the
basic.return
is sent asynchronously when a message is dropped in broker. When message was sent successfully no data is reported from server.So pyAMQP can't listen for such messages.
I've read few threads about this problem. Possible solution were:
basic.return
messages when they arrive.Because the level of support for pyAMQP and rabbitMQ in general is quite low, we decided not to use amqp broker at all.
您是否尝试过唯一完整的 Python AMQP 库?它没有被广泛使用,因为它的包装不整齐。
步骤 1. 编译 C 库 - 您可能需要
sudo apt-get install autotools-dev autoconf automake libtool
步骤 2. 安装 Python 库
Have you tried the only Python AMQP library that is complete? It isn't as widely used because it is not neatly packaged.
Step 1. compile the C library - you may need
sudo apt-get install autotools-dev autoconf automake libtool
Step 2. Install the Python library
您无法同步执行此操作,因为它是异步系统。但你可以使用线程来解决这个问题。
基本思想是启动一个在通道上等待的线程,每当它退出等待时,它都会为返回消息队列中的任何返回消息调用 call_back 函数。
然后,您可以在 call_back 函数中按照您想要的方式处理该消息
You can't do this synchronously as it is an asynchronous system. But you can solve this problem using threads.
The basic idea is that you start a thread which does the wait on the channel, whenever it comes out of the wait it calls the call_back function for any returned message in the returned message queue.
You can then deal with that message however you want to in the call_back function