Java Reference
In-Depth Information
context.createProducer().setAsync(new
Completion()).send(destination, "Hello world");
}
}
class Completion implements CompletionListener{
public void onCompletion(Message message)
{
System.out.println("message sent
successfully");
}
public void onException(Message message,
Exception ex) {
System.out.println(ex.getMessage());
}
}
Delivery delay
In addition to the possibility of sending messages asynchronously, JMS now permits
us to defer the time of delivery of a message already in the broker , which is a MOM
server. After sending, the message will be stored at the broker, but it will stay un-
known to the receiver until the time fixed by the sender. The message of the follow-
ing code will be delivered to the recipient at least one hour after sending.
public void
sendMessageWithDelay(ConnectionFactory
cfactory,Queue destination){
try(JMSContext context =
cfactory.createContext();){
context.createProducer().setDeliveryDelay(1000*60*60).send(destination,
"Hello world");
}
}
Search WWH ::




Custom Search