在使用 Python 的 Qpid Proton AMQP Messenger API 发送消息时,我正拼命尝试处理错误。
这是一个示例消息发送 session ,当发送到 localhost
上运行的 Qpid 代理上不存在的队列 myqueue
时,交互式 Python 解释器发送 session :
>>> from proton import *
>>> mng = Messenger()
>>> mng.timeout = 2000L
>>> m = Message()
>>> m.address = 'amqp://localhost/myqueue'
>>> m.subject = 'Test message'
>>> tracker = mng.put(m)
>>> repr(mng.status(tracker)) # status before send
'None'
>>> ret = mng.send() # send unconditionally returns None
LINK ERROR (amqp:not-found) Node not found: myqueue
>>> repr(mng.status(tracker)) # status after send
'None'
>>> mng.stop()
LINK ERROR
直接打印到 stdout(或 stderr),并且没有任何迹象表明消息未在 API 中传递。当消息位于缓冲区中时,status() 调用在发送之前返回 None;当消息被删除时,status() 调用也会返回 None。
我错过了什么吗?
使用Python 2.7、Qpid Proton 0.7。
最佳答案
最后。我读到关于信使的属性 outgoing_window
默认为 0。它是跟踪的传出消息的数量。将其设置为更高的数字可以解决问题:
>>> from proton import *
>>> mng = Messenger()
>>> mng.timeout = 2000L
>>> mng.outgoing_window = 1
>>> m = Message()
>>> m.address = 'amqp://localhost/myqueue'
>>> m.subject = 'Test message'
>>> tracker = mng.put(m)
>>> repr(mng.status(tracker))
'PENDING'
>>> ret = mng.send()
LINK ERROR (amqp:not-found) Node not found: myqueue
>>> repr(mng.status(tracker))
'ABORTED'
>>> mng.stop()
现在我可以跟踪邮件的状态并看到它已已中止。
关于python - Qpid Proton Messenger API 错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24783557/