21.3.2. Streaming over JMS
When using JMS, HornetQ maps the streaming methods on the core API (see Table 21.1, “org.hornetq.api.core.client.ClientMessage API”) by setting object properties. You can use the method
Message.setObjectProperty
to set the input and output streams.
The
InputStream
can be defined through the JMS Object Property JMS_HQ_InputStream on messages being sent:
BytesMessage message = session.createBytesMessage(); FileInputStream fileInputStream = new FileInputStream(fileInput); BufferedInputStream bufferedInput = new BufferedInputStream(fileInputStream); message.setObjectProperty("JMS_HQ_InputStream", bufferedInput); someProducer.send(message);
The
OutputStream
can be set through the JMS Object Property JMS_HQ_SaveStream on messages being received in a blocking way.
BytesMessage messageReceived = (BytesMessage)messageConsumer.receive(120000); File outputFile = new File("huge_message_received.dat"); FileOutputStream fileOutputStream = new FileOutputStream(outputFile); BufferedOutputStream bufferedOutput = new BufferedOutputStream(fileOutputStream); // This will block until the entire content is saved on disk messageReceived.setObjectProperty("JMS_HQ_SaveStream", bufferedOutput);
Setting the
OutputStream
could also be done in a non-blocking way using the property JMS_HQ_OutputStream.
// This will not wait the stream to finish. You need to keep the consumer active. messageReceived.setObjectProperty("JMS_HQ_OutputStream", bufferedOutput);
Note
When using JMS, Streaming large messages are only supported on
StreamMessage
and BytesMessage
.