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,
托马斯.
import sysfrom proton import *#This code is for initiating the AMQP messengeramqpmng = Messenger()amqpmng._set_timeout(2000L) #Set timeout for sending and receiving at 2000 msaddress = "amqp://owner:<longpassword>@<namespace>.servicebus.windows.net/<queuename>" #This code is for creating messagesmsg = Message()msg.subject = "This is a testmessage"msg.body = "Lorem ipsum dolor sit amet,consectetuer adipiscing elit."#This code is for sending messagestry: 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 messagesamqpmng.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类dict来映射他的类属性.
如果它有用,请告诉我!
总结以上是内存溢出为你收集整理的使用Python绑定在Qpid Proton中设置自定义消息属性全部内容,希望文章能够帮你解决使用Python绑定在Qpid Proton中设置自定义消息属性所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)