1

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?

sree1611
  • 352
  • 1
  • 4
  • 18

2 Answers2

1

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

Prasanth
  • 96
  • 3
  • the above works only when camel start. but my requirement is to stop the route if MQ is not available in middle. – sree1611 Sep 11 '20 at 08:33
  • you could write a timer route, that does a health check on the JMS connection (enable them using spring-boot actuator). Once health check fails, stop the route and enable them when the connection is healthy – srikant_mantha May 12 '21 at 18:48
0

@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().

Raju Parashar
  • 312
  • 4
  • 17