Lost Connections
When the network connection between the client and server is lost,
a JMS provider must make every reasonable attempt to reestablish the
connection. In the event that the JMS provider cannot automatically
reconnect, the provider must notify the client of this condition by
throwing an exception when the client invokes a method that would cause
network traffic to occur. However, it is reasonable to expect that a JMS
client may only be a receiver using the MessageListener interface, and not a producer
that makes any outbound publish() or
send() calls. In this case, the
client is not invoking JMS methods—it is just listening for messages—so
a dropped connection may not be detected.
JMS provides an ExceptionListener interface for trapping a
lost connection and notifying the client of this condition. The ExceptionListener is bound to the
connection—unlike MessageListeners,
which are bound to sessions. The definition of the ExceptionListener is:
public interface ExceptionListener {
void onException(JMSException exception);
}It is the responsibility of the JMS provider to call the onException() method of all registered
ExceptionListeners after making
reasonable attempts to reestablish the connection automatically. The JMS
client can implement the ExceptionListener so that it can be alerted to
a lost connection and possibly attempt to reestablish the connection
manually.
How can the JMS provider call an ExceptionListener if the client has been disconnected? Every JMS provider ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access