Java Reference
In-Depth Information
• The PERSISTENT delivery mode, the default, instructs the JMS provider to take
extra care to ensure that a message is not lost in transit in case of a JMS provider
failure. A message sent with this delivery mode is logged to stable storage when it
is sent.
• The NON_PERSISTENT delivery mode does not require the JMS provider to store
the message or otherwise guarantee that it is not lost if the provider fails.
You can specify the delivery mode in either of two ways.
• You can use the setDeliveryMode method of the MessageProducer inter-
face to set the delivery mode for all messages sent by that producer. For example,
the following call sets the delivery mode to NON_PERSISTENT for a producer:
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
• You can use the long form of the send or the publish method to set the
delivery mode for a specific message. The second argument sets the delivery mode.
For example, the following send call sets the delivery mode for message to
NON_PERSISTENT :
producer.send(message, DeliveryMode.NON_PERSISTENT, 3, 10000);
The third and fourth arguments set the priority level and expiration time, which are
described in the next two subsections.
If you do not specify a delivery mode, the default is PERSISTENT . Using the
NON_PERSISTENT delivery mode may improve performance and reduce storage over-
head, but you should use it only if your application can afford to miss messages.
Setting Message Priority Levels
You can use message priority levels to instruct the JMS provider to deliver urgent mes-
sages first. You can set the priority level in either of two ways.
• You can use the setPriority method of the MessageProducer interface to
set the priority level for all messages sent by that producer. For example, the fol-
lowing call sets a priority level of 7 for a producer:
producer.setPriority(7);
• You can use the long form of the send or the publish method to set the priority
level for a specific message. The third argument sets the priority level. For ex-
ample, the following send call sets the priority level for message to 3:
Search WWH ::




Custom Search