python qpid消息编码
我正在尝试使用 python 接收来自 amqp 代理的消息。这是我的代码:
#!/usr/bin/python
import sys
import os
import getopt
from qpid.messaging import *
from qpid.log import enable, DEBUG
broker_rcv = "admin/admin@hostname:IP"
address_rcv = "broadcast.QUEUE_NAME.QUEUE_NAME" + "; { node: { type: queue }, assert: never , create: never, mode: " + "browse" + " }"
connection_rcv = Connection(broker_rcv)
connection_rcv.open()
session_rcv = connection_rcv.session()
receiver = session_rcv.receiver(address_rcv)
msg = receiver.fetch(timeout=None)
print msg.content
但是当我尝试打印消息时,我看到它们采用奇怪的编码,并且无法更改消息编码。
我做错了什么?
I'm trying to receive messages from amqp broker in python. Here is my code:
#!/usr/bin/python
import sys
import os
import getopt
from qpid.messaging import *
from qpid.log import enable, DEBUG
broker_rcv = "admin/admin@hostname:IP"
address_rcv = "broadcast.QUEUE_NAME.QUEUE_NAME" + "; { node: { type: queue }, assert: never , create: never, mode: " + "browse" + " }"
connection_rcv = Connection(broker_rcv)
connection_rcv.open()
session_rcv = connection_rcv.session()
receiver = session_rcv.receiver(address_rcv)
msg = receiver.fetch(timeout=None)
print msg.content
But when I try to print messages I see them in strange encoding and there is no way how to change message encoding.
What I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
msg.content 包含某个生产者发送的原始消息内容。你无法改变它。
你上面提到的编码是什么?如果您在打印消息时看到这一点,请忽略它。
msg.content contains the original message content sent by some producer. You cannot change it.
And what is the encoding you metioned above? If you saw that when print msg, just ignore it.
你做错的是你无法解码消息。当您收到编码消息时,您必须首先对其进行解码。
这些是 FIX 消息吗?所有技术规范都在这里 http://fixprotocol.org/specifications/
这里有一个 Python 库 http://source.kentyde.com/fixlib
What you are doing wrong is that you are failing to decode the messages. When you receive an encoded message, you have to begin by decoding it.
Are those FIX messages? All the technical specs are here http://fixprotocol.org/specifications/
One Python library is here http://source.kentyde.com/fixlib