21.4. Streaming Alternative
If you choose not to use the
InputStream
or OutputStream
capability of HornetQ, the data can still be accessed directly in an alternative fashion.
On the Core API, get the bytes of the body as described in Chapter 7, Using Core.
ClientMessage msg = consumer.receive(); byte[] bytes = new byte[1024]; for (int i = 0 ; i < msg.getBodySize(); i += bytes.length) { msg.getBody().readBytes(bytes); // Whatever you want to do with the bytes }
If using JMS API,
BytesMessage
and StreamMessage
also supports it transparently.
BytesMessage rm = (BytesMessage)cons.receive(10000); byte data[] = new byte[1024]; for (int i = 0; i < rm.getBodyLength(); i += 1024) { int numberOfBytes = rm.readBytes(data); // Do whatever you want with the data }