1 Reply Latest reply on Nov 6, 2013 12:40 PM by Clebert Suconic

    JMSClient receive message convert to byte data and restore queue

    Uichi Hasegawa Newbie

      I use version Hornetq 2.2.5.Final.

      I want to make message client side:

      (1) Received message from the HornetQ server, converts to byte array.

      (2) Restore the message from byte array, and send message to the HornetQ server.


      I have tried to use "org.hornetq.core.message.impl.MessageImpl#encode, decode".

      but miss to restore messages, message body is null. I wrote to following code.

      Is my way wrong?

      who knows how to do the other?



              // convert to byte array

              Message message = consumer.receiveNoWait();

              HornetQMessage hornetQMessage = (HornetQMessage) message;

              ClientMessage clientMessage = hornetQMessage.getCoreMessage();

              MessageImpl messageImpl = (MessageImpl) clientMessage;

              int encodeSize = messageImpl.getEncodeSize();

              byte[] array = new byte[encodeSize];

              ByteBuffer byteBuffer = ByteBuffer.wrap(array);

              HornetQBuffer buffer = HornetQBuffers.wrappedBuffer(byteBuffer);


              // output byte array to file....



              // input byte array from file....

              //restore message from byte array

              ClientSession coreSession = ((HornetQSession) session).getCoreSession();

              ClientMessage clientMessage = coreSession.createMessage(true);

              MessageImpl messageImpl = (MessageImpl) clientMessage;

              HornetQBuffer buff = HornetQBuffers.dynamicBuffer(array);


              HornetQMessage hornetQMessage = HornetQMessage.createMessage((ClientMessage) messageImpl, coreSession);