py-amqp/flopsy:在 Python 中等待单个 AMQP 消息
我有一个类似的问题这个:在 py-amqp/flopsy 中很容易说“我将永远等待,并且我希望每当有消息传入时就调用此回调”,但我找不到任何方式说“好吧,我得到了我现在想要的消息,别再等待了。” (也许是 GOTO?开个玩笑......)有没有一种优雅的方式来做到这一点?
I have a similar question to this one: It's very easy in py-amqp/flopsy to say "I'm going to wait forever, and I want this callback to be called whenever a message comes in," but I can't find any way of saying "OK, I got the message I want now stop waiting." (Maybe a GOTO? Just kidding...) Is there an elegant way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,也许这对我来说应该是显而易见的:如果您在 flopsy(这是 amqplib 的一个薄包装器)中注册一个回调,那么
您可以在
callback_func
中引发
异常获取代码的其余部分。额外问题:如果从未收到响应,如何设置
wait()
的最大超时时间?假设这是在unittest
测试用例的上下文中。OK, maybe this should have been obvious to me: If you register a callback in flopsy (which is a thin wrapper around amqplib) with
then you can
raise
an Exception incallback_func
to get to the rest of the code.Bonus question: How do I set a maximum timeout for the
wait()
in case a response is never received? Let's say that this is in the context of aunittest
test case.