Java Reference
In-Depth Information
Message Delivery Delay
The JMS API provides a method, setDeliveryDelay , which can be applied to producers. This method can be called,
passing the delay time in milliseconds, prior to sending the message. Once the delay has been set, this will cause all
subsequent message deliveries by that producer to be delayed by the specified time.
Set the time of delay in milliseconds by calling the producer's setDeliveryDelay(long) method. In the following
example, the message sending will be delayed by 1,000 milliseconds.
@Resource(name = "jms/topicConnFactory")
private TopicConnectionFactory topicConnFactory;
@Resource(lookup = "jms/Topic")
Topic topic;
public void publishMessage() throws NamingException, JMSException {
TopicConnection topicConnection = topicConnFactory.createTopicConnection();
topicConnection.start();
TopicSession topicSession =
topicConnection.createTopicSession(false, QueueSession.AUTO_ACKNOWLEDGE);
Topic topic = topicSession.createTopic("JavaEE");
TextMessage textMessage = topicSession.createTextMessage("This is a test message");
javax.jms.TopicPublisher topicPublisher = topicSession.createPublisher(topic);
topicPublisher.setDeliveryDelay(1000);
topicPublisher.publish(textMessage);
topicSession.close();
topicConnection.close();
}
New Send Methods for Asynchronous Sending
JMS clients have the ability to send messages synchronously and asynchronously via a JMS message producer. In JMS
2.0, new send methods have been added for asynchronous message sending. Sending a message asynchronously
allows the sending of a task to be performed in a separate thread from other tasks that are being performed. When
using the classic API, the following methods allow for asynchronous sending:
send(Message message, CompletionListener listener)
send(Message message, int deliveryMode, int priority, long timeToLive,
CompletionListener completionListener)
send(Destination destination, Message message, CompletionListener
completionListener)
send(Destination destination, Message message, int deliveryMode, int priority,
long timeToLive, CompletionListener completionListener)
 
Search WWH ::




Custom Search