[英]python proton API on_accepted() - how do I get the details of the msg being accepted, from the event parameter?
There are a dozen "hello world" type examples I see where on_accepted()
just counts the number of accepted msgs - where it is something to show that "a message" was accepted.我看到有十几个“hello world”类型的例子,其中
on_accepted()
只计算接受的消息的数量 - 它表明“消息”被接受。 However, I need to know WHICH message was accepted.但是,我需要知道接受了哪个消息。
def on_accepted(self, event):
m_id = event.message.id
self.logger.info( 'Accepted msg {0}'.format( m_id ))
This doesn't work because there is no valid message element in event, so I end up with a NoneType doesn't have an id
type error.这不起作用,因为事件中没有有效的消息元素,所以我最终得到一个
NoneType doesn't have an id
类型错误。
I looked at the members of the event parameter and I don't see anything which I thought would make sense..我查看了事件参数的成员,但没有看到任何我认为有意义的内容。
I wasn't able to find any references to how to read the message details, but I was able to find a work around which gave me the same info.我无法找到有关如何阅读消息详细信息的任何参考资料,但我找到了一种解决方法,该方法为我提供了相同的信息。
If I specify a tag on the send() call, like this:如果我在 send() 调用上指定一个标签,如下所示:
event.sender.send(msg, tag = msg_id )
I can then read it in the receiver code like this:然后我可以在接收器代码中读取它,如下所示:
def on_accepted(self, event): msg_id = event.delivery.tag
Problem "solved"问题解决了”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.