-
1. Re: Produce using Core, consume using JMS
clebert.suconic Jan 29, 2013 10:46 PM (in response to dlopezleon)I would use CoreMessage on your producer instead of the JMS Message.
The JMS Messages are encapsulating the core-message. The JMs Wrapper will convert them to core-message right before sending.
In case you want to send a TextMessage that will be received as a text message, on that case you will have to look at the encoding done on HOrnetQTextMessage, or use HornetQTextMessage directly to create your core message
hint: there's a method to expose the core message on HornetQMessage which is what you need.
-
2. Re: Produce using Core, consume using JMS
dlopezleon Jan 30, 2013 7:49 AM (in response to clebert.suconic)Clebert Suconic wrote:
I would use CoreMessage on your producer instead of the JMS Message.
I think I'm producing CoreMessages. This is a snippet of my producer code
ClientMessage message = session.createMessage(true); message.getBodyBuffer().writeBytes(toByteArray(messagePayload)); producer.send(message); message.acknowledge();
Then I'm consuming those messages in another app, via Spring's JmsTemplate, as an ObjectMessage.
It's worth to mention that producing JMS messages using hornetq-jms-client to that queue works flawessly, but I always try to keep my dependencies to the minumum, that's why I would prefer to produce those messages using core
-
3. Re: Produce using Core, consume using JMS
clebert.suconic Jan 30, 2013 11:36 AM (in response to dlopezleon)That's what I was referring to the body and content of the message...
If you want to be able to cast it to ObjectMessage, you need to oby the protocol the JMS Producer would have to send the message.
For starter, you could use createMessag(byte type, boolean durable) signature...
You would have to pass the HornetQObjectMessage.TYPE (which is the same to Message.OBJECT_TYPE = 2)...
On the body of your message, you would have to write an Integer with the size of the array, and the data from the ObjectOUtputStream:
Look at setObject:
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(object);
oos.flush();
data = baos.toByteArray();
And Look at before sen:
message.getBodyBuffer().writeInt(data.length);
message.getBodyBuffer().writeBytes(data);
So, on your producer you would have to do this:
ClientMessage msg = session.createMessage(Message.OBJECT_TYPE, true);
byte [] payload = SomeSerializationUtil.covertToByteArray(someObject);
msg.getBodyBuffer().writeInt(message.length);
msg.getBodyBuffer().writeBytes(payload);
ˆˆ^something like this... notice that I didn't test this code.. consider this as pseudo-english.
-
4. Re: Produce using Core, consume using JMS
clebert.suconic Jan 30, 2013 11:37 AM (in response to clebert.suconic)One thing you could do also is directly instantiate HornetQObjectMessage and use it directly. But there's no guarantee that internal APIs will never change. If you do the method I wrote on the previous post it should work fine.