sree1611
sree1611

Reputation: 362

Stop camel route if MQ becomes unavailable

I have one of the camel route as follows, there are many routes.

  from("jms:queue:TEST.LQ?transacted=true&connectionFactory=jmsConnectionFactory&cacheLevelName=CACHE_NONE")
  .routeId("routeid")
  .autoStartup("true")
  .transacted("requried")
  ....
  ....

I getting below error if TEST.LQ MQ or Queue manager is unavailable.

 ERROR [JmsConsumer[TEST.LQ]] [] [o.a.c.c.j.DefaultJmsMessageListenerContainer      ] Could not refresh JMS Connection for destination

I tried to handle exception by catching below code, but JmsMessageListenerContainer only throws the message not an exceptiom

 onException(MQException.class, JMSException.class)

How stop route if IF MQ is not available?

Upvotes: 1

Views: 429

Answers (2)

Raju Parashar
Raju Parashar

Reputation: 322

@sree1611,

You can add exceptionListener or errorHandler query parameter in camel jms uri. To create your own exception listener, implement org.apache.camel.spi.ExceptionHandler To create your own error handler, implement org.springframework.util.ErrorHandler

I hope errors while consuming from MQ can't be bridged with camel error handlers, so you can't catch JMS exceptions (occurred during message consumption from MQ) in onException().

Upvotes: 0

Prasanth
Prasanth

Reputation: 96

The camel jms component has the option for this -

Add the testConnectionOnStartup=true option in your from(uri) :

from("jms:queue:TEST.LQ?transacted=true&connectionFactory=jmsConnectionFactory&cacheLevelName=CACHE_NONE&testConnectionOnStartup=true")

This will throw an exception if a connection is not available during startup which can then be handled.

More details are available in the jms-component page

Upvotes: 1

Related Questions