Question

I have a route which is for reading items from JMS queue and writing them into DB.

I have read the documents about Apache Camel JMS component but I did not get the exact and clear answer of my question, which is "Does a JMS Consumer re-insert the item or unlock the message in the JMS queue if some exception occurs in a route?".

Thanks

Ali

Was it helpful?

Solution

You can read about transactions here: http://camel.apache.org/transactional-client.html

A JMS consumer in transacted mode will keep the message in the queue, until the TX is committed.

If the TX does a rollback, then the JMS Broker will redeliver the message again. You can configure the JMS broker to do this X times, and if still failing move the message to a dead letter queue.

This is JMS broker specific how its configured out of the box etc. For Apache ActiveMQ see details at: http://activemq.apache.org/message-redelivery-and-dlq-handling.html

If you have a copy of Camel in Action book then this is covered in much more details in chapter 9. Figure 9.6 illustrates how all this work.

OTHER TIPS

As mentioned in other answers too, there are few things to remember:

  1. Camel provides only a javax.jms.MessageListener impl to Spring. Its Spring's DMLC (DefaultMessageListenerContainer) and related classes which are doing all the heavy lifting.

  2. Definition of a Camel route actually registers a listener instance which will get invoked in a try-catch block by Spring later on when DMLC will receive a msg from JMS broker. That means your consumer route is always invoked in context controlled by Spring.

  3. If there are un-handled errors in route, Spring will catch them and will "rollback". If the route completed successfully, Spring will "commit" the JMS message which means msg will be removed off broker queue.

If you wish to understand whats happening underneath in detail, read this post: http://krasnikov-tube.blogspot.sg/2014/02/where-apache-camel-meets-spring-jms.html

Hope that will help.

It also depends on how you are configuring your route. for the message to back to your queue, your need to configure your components to be transactional. The exception handling in your route need to let the exception bubble up, if you set "handled" to true the exceptions will not bubble up and you will lose the message.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top