Hi, 

You probably need to serialize the object first. 

RabbitMQ per-se doesn't care about the content of what you publish.

-Alvaro 

-- 
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Saturday, May 12, 2012 at 11:44 AM, aluen wrote:

> 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 (http://self.name) = name
> self.body = body
> def set_name(self,name):
> self.name (http://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!!
> 
> _______________________________________________
> rabbitmq-discuss mailing list
> [email protected] 
> (mailto:[email protected])
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
> 
> 


-- 
You received this message because you are subscribed to the Google Groups 
"rabbitmq-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rabbitmq-discuss?hl=en.

Reply via email to