Search code examples
jmsactivemq-artemis

ActiveMQ Artemis crash re-connect


My ActiveMQ Artemis 2.32.0 in K8s pod keeps crashing for some reason. After the crash and pod restart my existing clients get this exception:

org.apache.qpid.jms.exceptions.JmsConnectionFailedException: The JMS connection has failed: Transport connection remotely closed.`
org.apache.qpid.jms.provider.exceptions.ProviderFailedException: Transport connection remotely closed.

I am creating the connection using this code:

ConnectionFactory connectionFactory = new JmsConnectionFactory(activeMqAmpq);
Connection connection = connectionFactory.createConnection();

I do not see any methods to check if the connection is still active or alive. I have read about reconnecting automatically and apparently is not possible after a crash. Hence I would like to know if the connection is still active. If not, then I can re-connect before creating a session and sending a message.


Solution

  • JMS doesn't provide any methods to check whether the connection is active or not. You should simply use the connection and if any exceptions are thrown then you should deal with them accordingly (e.g. invoke close() on the existing Connection and use the ConnectionFactory to create another one).

    If you happen to be using a MessageListener and are therefore waiting for a callback (i.e. not actively invoking JMS methods) then you should register an ExceptionListener using Connection.setExceptionListener().

    Aside from this you might try using the automatic reconnection features available in the Qpid JMS client you're using. Even if you aren't using multiple instances of ActiveMQ Artemis you should still be able to use a URL with a single broker, e.g.:

    failover:(amqp://host:5672)?failover.maxReconnectAttempts=20