[rabbitmq-discuss] Serialized Java Objects in Message bodies not supported by RabbitMQ??

Jerry Kuch jerryk at vmware.com
Mon Mar 5 21:21:57 GMT 2012


Hi, Ashutosh:

(Copying back on the list in case others or future Google-searchers
are interested...)

If you *really* want to serialize your Java object to a bytestream
you can send in an AMQP message body you could do something like this:

ByteArrayOutputStream os = new ByteArrayOutputStream();
ObjectOutput objOut = new ObjectOutputStream(os);

objOut.writeObject(whateverYourObjectIs);
byte byteForm[] = os.toByteArray();
objOut.close();
os.close();

That said, you might still want to think carefully about whether you want 
to do this and have your application cope with the restrictions it imposes,
and the pitfalls (potential bugs, security holes, maintenance and testing
costs, etc.) it creates.  The sections on Serialization in chapter
11 of Josh Bloch's "Effective Java" are something you may want to keep
close at hand.

Best regards,
Jerry

----- Original Message -----
From: "Ashutosh Mathur" <amathur.q at gmail.com>
To: "Jerry Kuch" <jerryk at vmware.com>
Sent: Sunday, March 4, 2012 8:07:07 PM
Subject: Re: [rabbitmq-discuss] Serialized Java Objects in Message bodies not supported by RabbitMQ??

Hi Jerry, 

Thanks for the reply.Now its almost clear to me that we can send Java Serialized objects in message bodies.But I had read on some discussion groups elsewhere that this is not possible.If it is possible,as you say, can you please specify a method which will do so?Can we use the normal "MessageConverters" for this? 
Sorry for the mail in your personal mailbox.Wasn't sure whether you'll see this post in the discussion lists. 

Ashutosh 


On Fri, Mar 2, 2012 at 10:41 AM, Jerry Kuch < jerryk at vmware.com > wrote: 


Hi, Ashutosh: 

You can put any bytes you want into an AMQP message payload, 
you'll just have to handle the encoding yourself in the usual 
Java serialization ways. Be warned though, that serializing POJOs 
is going to put restrictions on the the recipients of your message 
can be, i.e. they're also going to need to be in Java, with the 
appropriate stuff versions of the appropriate stuff on their 
classpaths, to be able to make sense out of what you're sending 
them if you plan to deserialize them into Java objects. 

You might find the JSON solution you suggest gives you something 
that's a bit more friendly in polyglot systems, and leave your 
application with more future flexibility... 

Jerry 



----- Original Message ----- 
From: "Ashutosh Mathur" < amathur.q at gmail.com > 
To: rabbitmq-discuss at lists.rabbitmq.com 
Sent: Thursday, March 1, 2012 9:00:36 PM 
Subject: [rabbitmq-discuss] Serialized Java Objects in Message bodies not supported by RabbitMQ?? 


Hi, 

RabbitMQ doesn't support Serialized Java Objects in Message bodies.Is that true? In JMS,it is done by "CreateObjectMessage()" method. Is there any function in AMQP which has same/similar functionality.? 
One possible solution for above may be to convert data into JSON strings and send within the message.will that work? 
Thanks in advance. 

_______________________________________________ 
rabbitmq-discuss mailing list 
rabbitmq-discuss at lists.rabbitmq.com 
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss 



More information about the rabbitmq-discuss mailing list