Set an Exception Listener
All the APIs support the ability to set an exception listener on the connection that gets invoked when a connection breaks or experiences a fault-tolerant failover.
When the event is a disconnect, the exception handler can call various EMS methods without any problem. However, when the event is a fault-tolerant failover, the exception handler is not allowed to call any EMS method. To do so risks a deadlock. You can call the
setExceptionOnFTSwitch
method to receive an exception that contains the new server URL after a fault-tolerant failover has occurred.
The following examples demonstrate how to establish an exception listener for a connection.
- Java
Implement an
ExceptionListener.onException
method, use theConnection
object’ssetExceptionListener
method to register the exception listener, and callTibjms.setExceptionOnFTSwitch
to call the exception handler after a fault-tolerant failover:public class tibjmsMsgConsumer
implements ExceptionListener
{
.....
public void onException(JMSException e)
{
/* Handle exception */
}
.....
connection.setExceptionListener(this);
com.tibco.tibjms.Tibjms.setExceptionOnFTSwitch(true);
.....
}See the
tibjmsMsgConsumer.java
sample client for a working example (without thesetExceptionOnFTSwitch
call). - C
Define an
onException
function to handle exceptions,
use thetibemsConnection_SetExceptionListener
function to callonException
when an error is encountered, and calltibems_setExceptionOnFTSwitch
to call the exception handler after a fault-tolerant failover:void onException( tibemsConnection conn, tibems_status reason, void* closure) { /* Handle exception */ } ..... status = tibemsConnection_SetExceptionListener( connection, onException, NULL); tibems_setExceptionOnFTSwitch(TIBEMS_TRUE);
See the
tibemsMsgConsumer.c
sample client for a working example (without thesetExceptionOnFTSwitch
call). - C#
Implement an
IExceptionListener.OnException
method, set theConnection
object’sExceptionListener
property to register the exception listener, and callTibems.SetExceptionOnFTSwitch
to call the exception handler after a fault-tolerant failover:public class csMsgConsumer : IExceptionListener {
..... public void OnException(EMSException e) { /* Handle exception */ } ..... connection.ExceptionListener = this; TIBCO.EMS.Tibems.SetExceptionOnFTSwitch(true); ..... }See the csMsgConsumer.cs sample client for a working example (without the
setExceptionOnFTSwitch
call).