← Back to team overview

txamqp-user team mailing list archive

pickling objects through amqp

 

hi everybody,
i'm prototyping an app that should use txamqp and rabbitmq.
I need to send python objects through the queues via txamqp.
I was thinking about using pickle to serialize objects, but doesn't
seems to function.
I've downloaded two example files from esteve fernandez that are
called txamqp_consumer.py and txamqp_publisher.py.
I've modified only these lines:

txamqp_consumer.py
def recv_callback(msg, chan, queue):
    print 'Received: ' + msg.content.body + ' from channel #' + str(chan.id)
    return (queue.get().addCallback(recv_callback, chan, queue))

in

def recv_callback(msg, chan, queue):
    msgbody = pickle.dumps(msg.content.body)
    print 'Received: ' + msgbody + ' from channel #' + str(chan.id)
    return (queue.get().addCallback(recv_callback, chan, queue))

txamqp_publisher.py
msg = Content(body)

in

msg = Content(pickle.loads({'a':123,'b':456}))

As you can see i try to send a simple dict.
But on the consumer i receive only garbled strings that aren't
converted back to normal object by pickle.
Is this normal or am i missing something?

This is the output:
Received: S"(dp0\nS'a'\np1\nI123\nsS'b'\np2\nI456\ns."
p0
. from channel #1

It seems that the newlines aren't treated as new line...
What i'm missing?
Thanks in advance for any help.



Follow ups