Detecting disconnect using mq-jms-spring from IBM

Viewed 198

I am trying to write a health check for our JMS connection that connects to MQ using IBM JMS integrations code ibm-messaging/mq-jms-spring. I need to detect that the connection to MQ has been lost. I hooked the exceptionListener for the DefaultJmsListenerContainerFactory and that tells me when I lose the connection to MQ but I cannot find anything in the JMS stack that tells me when the connection gets (re)established.

Code that calls the ExceptionListener

    @Override
protected void establishSharedConnection() {
    try {
        super.establishSharedConnection();
    }
    catch (Exception ex) {
        if (ex instanceof JMSException) {
            invokeExceptionListener((JMSException) ex);
        }
        logger.debug("Could not establish shared JMS Connection - " +
                "leaving it up to asynchronous invokers to establish a Connection as soon as possible", ex);
    }
}
2 Answers

From a strictly JMS perspective, when the onException method of your ExceptionListener is invoked it is up to your application to re-establish the JMS connection using ConnectionFactory.createConnection. This is a blocking call so once it returns successfully then you know the connection has been re-established.

If you're delegating the JMS connection management to Spring it's unlikely you will be able to be informed about when the JMS connection is re-established. I don't see any hooks in Spring JMS for this.

One thing that I have observed last week is that if MQ is coded or configured to use the reconnect functionality then an ExceptionListener receives a message from the queue manager when a reconnection is made.

Related