O'Reilly - Java Message Service
O'Reilly - Java Message Service
O'Reilly - Java Message Service
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
...<br />
}<br />
{<br />
try {<br />
Thread.sleep(10000);<br />
} catch (java.lang.InterruptedException ie) { }<br />
continue;<br />
}<br />
}<br />
System.out.println("\nConnection established");<br />
<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />
The establishConnection( ) method then registers the ExceptionListener with the<br />
connection via the setExceptionListener( ) method:<br />
connect.setExceptionListener( (javax.jms.ExceptionListener) this);<br />
Last, but not least, is the implementation of the onException( ) listener method. Its task is<br />
to call the establishConnection( ) method again to re-establish a connection with the<br />
JMS provider:<br />
public void onException ( javax.jms.JMSException jmse)<br />
{<br />
// Tell the user that there is a problem<br />
System.err.println ("\n\nThere is a problem with the connection.");<br />
System.err.println (" JMSException: " + jmse.get<strong>Message</strong>( ));<br />
}<br />
System.err.println ("Please wait while the application tries to "+<br />
"reestablish the connection...");<br />
connect = null;<br />
establishConnection(mBroker, mUsername, mPassword);<br />
When a connection is dropped and reestablished, all of the sessions, queues, publishers,<br />
and subscribers need to be reestablished in order for the application to continue normal<br />
processing. This is why we isolated all the connection logic in the establishConnection( )<br />
method, so that it can be used during startup and reused if the connection is lost.<br />
JMS does not define any reason codes for a dropped connection. However, a JMS provider<br />
may provide a finer level of granularity by defining reason codes. Depending on the host<br />
operating system's network settings, it may take a while for the provider to notice that a<br />
connection has been dropped. Some providers implement a ping capability as a<br />
configurable setting to detect a network loss.<br />
6.6 Dead <strong>Message</strong> Queues<br />
JMS provides mechanisms for guaranteed delivery of messages between clients, utilizing<br />
the mechanisms we have discussed in this chapter. However, there are cases where<br />
guaranteed delivery, acknowledgments, and transactional semantics are just not enough.<br />
Many conditions may cause a message to be undeliverable. <strong>Message</strong>s may expire before<br />
they reach their intended destination, or messages are viewed by the provider as<br />
undeliverable due to some other reason such as a deployment configuration problem. A<br />
message need not have an expiration associated with it, which means it would never<br />
expire. Forever is a long time. Realistically, it would be more prudent if the JMS provider<br />
could notify an application if a message cannot be delivered within a reasonable amount of<br />
time.<br />
106