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.onExceptionmethod, use theConnectionobject’ssetExceptionListenermethod to register the exception listener, and callTibjms.setExceptionOnFTSwitchto 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.javasample client for a working example (without thesetExceptionOnFTSwitchcall). - C
Define an
onExceptionfunction to handle exceptions,
use thetibemsConnection_SetExceptionListenerfunction to callonExceptionwhen an error is encountered, and calltibems_setExceptionOnFTSwitchto 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.csample client for a working example (without thesetExceptionOnFTSwitchcall). - C#
Implement an
IExceptionListener.OnExceptionmethod, set theConnectionobject’sExceptionListenerproperty to register the exception listener, and callTibems.SetExceptionOnFTSwitchto 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
setExceptionOnFTSwitchcall).