0

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?

Dan D.
  • 73,243
  • 15
  • 104
  • 123
user1209304
  • 408
  • 1
  • 5
  • 26
  • Post some of the strangely encoded strings. – Blender Feb 14 '12 at 15:19
  • AEDEXCHAED"AEDN0 :UAE DIRHAMS @H R EURAED XLâ H ANGEXCHANG"ANGN0 :NETHERLANDS @H R EURANG XLâ H AUDEXCHAUD"AUDN0 :AUSTRAL DOLLAR@H R EURAUD XLâ H AZNEXCHAZN"AZNN0 :AZERBAIJAN @H R – user1209304 Feb 14 '12 at 15:25
  • If I delete print and left just msg.content I recive message like this: \n2\xa2\x06/\n\x0520001\x12\nEUREX 14.0\x1a\x05EUREX \x01*\x07\x08\xcd\x0f\x10\x0b\x18\x0c0\x00:\x06\x08\x0e\x10\x13\x18\x0e\x12L\x8a\xe2\tH\n\x03AED\x12\x04EXCH\x1a\x03AED"\ – user1209304 Feb 14 '12 at 15:28

2 Answers2

0

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.

Chenxiong Qi
  • 416
  • 3
  • 8
0

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

Michael Dillon
  • 31,973
  • 6
  • 70
  • 106