HornetQ Stomp Producer with Core/JMS Consumer

I had trouble sending a message via STOMP and consuming the message via the Core/JMS client API.

HornetQ’s StompProtocolManager adds the stomp message to the queue in a different way to other messages added via core or JMS.

To consume the contents of a stomp message, you cannot just call readNullableSimpleString();. You need to do some buffer manipulation first.

I got this hint from org.hornetq.core.protocol.stomp.StompSession.sendMessage().

            ClientConsumer messageConsumer = session.createConsumer(queueName);
            session.start();

            ClientMessage messageReceived = messageConsumer.receive(1000);

            HornetQBuffer buffer = messageReceived.getBodyBuffer();
            buffer.readerIndex(MessageImpl.BUFFER_HEADER_SPACE + DataConstants.SIZE_INT);
            SimpleString text = buffer.readNullableSimpleString();
            String myString = text.toString();
Leave a comment

2 Comments.

  1. Thank you so much for this ! Saved me a *lot* of time :grin:

Leave a Reply


[ Ctrl + Enter ]