Hi, I'm receiving messages from a JMS provider and need to control the 'acknowledgement' of the JMS messages depending on Exceptions I get from the message processing Java bean.
On technical Exceptions (i.e. database currently not available) I don't want to acknowledge the JMS message, so that it will be retrieved again and again until the database connection is available again. This is handled by setting the acknowledge mode 'SESSION_TRANSATED'. As soon as I have an exception the JMS message will not be acknowledged and be available for the 'next try'. But - on specific exceptions, I want to bypass the acknowledgement so that the JMS message will be acknowledged, even though the transaction will be rolled back. As an example: I do want to acknowledge the message on validation exceptions. I thought that setting the exception to 'handled = true' might solve the issue. @Component public class JmsEndpointRoute extends RouteBuilder { @Override public void configure() throws Exception { from("jms:myTopic?transacted=true&acknowledgementModeName=SESSION_TRANSACTED") .to("direct:importMessage"); } } @Component public class ImportMessageRoute extends RouteBuilder { @Override public void configure() throws Exception { onException(MyException.class).to("direct:processFailedMessage") .log("Import failed").handled(true); onException(Throwable.class).log("EXCEPTION -> rollback -> no acknowledgement"); from("direct:importMessage").transacted() .to("messageConsumer") .log("Message imported"); } } This does not work, the 'handled(true)' will be ignored in this scenario and the message will not be acknowledged. Is there another solution to handle this scenario? Best regards, Andreas