NonStop JMS User's Manual (NonStop JMS 2.0+)
NSJMS and JMS Client Applications
NonStop Server for Java Message Service User’s Manual—522356-002
3-9
Persistence
Persistence
NSJMS does not optimize for NON_PERSISTENT messages (deliver at most once). All
messages are treated as having PERSISTENT delivery mode (deliver once and only
once).
Priority
JMS allows message priority to be set by the setPriority() method on the
MessageProducer object and retrieved using the getPriority() method on the
MessageConsumer object. Although NSJMS allows message priority to be set and
retrieved, this priority does not affect message delivery order.
Receiving Messages
A JMS client uses a MessageConsumer to receive messages from a specified
destination. A message consumer is an object created by a session that is used by
JMS clients to receive messages from queues or topics. The PTP messaging
application uses QueueReceiver as its message consumer, and the Pub/Sub
messaging application uses TopicSubscriber as its message consumer.
Receiving Messages from a Queue
To receive a message from a queue, you create a QueueReceiver using the
createReceiver() method. This method uses a Queue parameter to define where
the messages are received from. This code fragment receives a message from a
queue and then reads back the message:
QueueReceiver receiver = session.createReceiver(queue);
Message message = receiver.receive();
The receive() method without parameters blocks indefinitely unless a timeout
parameter is specified. When specified, this parameter defines how long the
receive() method should wait when there are no messages available. There will be
no delay if the receiveNoWait() method is used.
The receive() method will return a message of the same type as was sent to the
queue. For example, if a StreamMessage is sent to a queue, the receive() method
will return an object of type StreamMessage.
In order to pull the content from the body of the message, you must identify the
subclass of the message contents, such as TextMessage. If you do not know the
message contents subclass, use instanceof to determine if the contents of a
message are of a certain type. It is good practice always to test the message class
before casting, so that unexpected errors are handled gracefully.