[rabbitmq-discuss] Can rabbitMQ publish an object to the queue?

aluen aluenkinglee at gmail.com
Sat May 12 10:44:01 BST 2012


I have learned the Tutorials <http://www.rabbitmq.com/getstarted.html> on 
the rabbitmq website  and  all the cases work well.So  I want to do more 
with it . 
I found that all the cases just publish a string to the queue ,can other 
object publish to queue? have a try . I did as follows:

*send.py*

# encoding=utf8
import pika

class message:
id = 1
name = ""
body = ""
def __init__(self,name="message",body="hello world"):
self.name = name
self.body = body
def set_name(self,name):
self.name = name
def set_body(self,body):
self.body = body
msg = message() *# I want to put this kind of object publish to the queue*

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='',
                      routing_key='hello',
                      body=msg)
print " [x] Sent 'Hello World!'"
connection.close()

then i run this script , and i got this warning:

Traceback (most recent call last):
  File "send.py", line 24, in <module>
    body=msg)
  File "build/bdist.linux-i686/egg/pika/adapters/blocking_connection.py", 
line 285, in basic_publish
  File "build/bdist.linux-i686/egg/pika/adapters/blocking_connection.py", 
line 241, in send_method
  File "build/bdist.linux-i686/egg/pika/connection.py", line 669, in 
_send_method
*AttributeError: message instance has no attribute '__len__'*

the underline words is what I want to ask,how to  deal with it , can I put 
an object to the queue because I hope to do like this ,do you have other 
method? Thanks!!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120512/477a4329/attachment.htm>


More information about the rabbitmq-discuss mailing list