gpt4 book ai didi

python - 使用 Python 绑定(bind)在 Qpid Proton 中设置自定义消息属性

转载 作者:太空宇宙 更新时间:2023-11-03 11:52:44 37 4
gpt4 key购买 nike

我正在尝试使用 Qpid Proton 的 Python 绑定(bind)发送带有自定义属性的消息,但我找不到正确的方法...

  message = Message()
message.body = u"hello body"
data = Data()
data.put_map()
data.enter()
data.put_string("key")
data.put_string("value")
data.exit()
message.properties = data
messenger.put(message)
messenger.send()

结果...

Traceback (most recent call last):
File "./candy_ingest.py", line 37, in <module>
messenger.put(message)
File "/usr/lib/python2.7/dist-packages/proton.py", line 473, in put
message._pre_encode()
File "/usr/lib/python2.7/dist-packages/proton.py", line 781, in _pre_encode
props.put_object(self.properties)
File "/usr/lib/python2.7/dist-packages/proton.py", line 2036, in put_object
putter = self.put_mappings[obj.__class__]
KeyError: <class proton.Data at 0x2320420>

欢迎任何帮助!

TIA,托马斯。

最佳答案

这是我用于将 RaspBerryPi 连接到 Windows Azure 服务总线的代码

import sys
from proton import *

#This code is for initiating the AMQP messenger
amqpmng = Messenger()
amqpmng._set_timeout(2000L) #Set timeout for sending and receiving at 2000 ms
address = "amqp://owner:<longpassword>@<namespace>.servicebus.windows.net/<queuename>"

#This code is for creating messages
msg = Message()
msg.subject = "This is a testmessage"
msg.body = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."

#This code is for sending messages
try:
msg.address = address
amqpmng.put(msg)
amqpmng.send()
except:
e = sys.exc_info()[0]
print e, "Waited for 2s to send messages, nothing send, connection timed out"

amqpmng.stop();

#This code is for receiving messages
amqpmng.subscribe(address)
amqpmng.start()
try:
amqpmng.recv(1) #receive exactly 1 message (you can enter any value)
msg = Message()
while amqpmng.incoming > 0:
amqpmng.get(msg)
print(msg.body)
except:
e = sys.exc_info()[0]
print e, "Waited for 2s to receive messages, nothing received, connection timed out"

amqpmng.stop()

消息类也只有两个以数据为参数的方法。

message.decode(data)
message.load(data)

我认为你应该使用 message.load(data)。

此外,我从 API 引用中了解到,message.properties 正在使用 python 类字典来映射他的类属性。

如果有帮助,请告诉我!

关于python - 使用 Python 绑定(bind)在 Qpid Proton 中设置自定义消息属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22142717/

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