I am trying to run a camel transacted() route (a standalone java process) with JPATransactionManager is the spring PlatformTransactionManager (as I want camel route to run in a single DB transaction) but I am not able to suppress redelivery from MQ Broker in case a transactional method fails even though I have used handled(true) in onException clause along with my custom redelivery policy (which is executed successfully). I only want MQ to redeliver when there is a service crash.
Tried below but it doesn't work:
- Setting setTransacted(false) in JMSComponent config so as to prevent camel jms to run is transacted_session jms mode but it does not work
- doTry and doCatch the exception from transactional block
camel redeliveries followed by handled(true).
onException(Exception.class) .log("ERROR OCCURRED") .redeliveryPolicyRef("myRedeliveryPolicy") .handled(true) .to(getPostExceptionRoute()); @Bean @Autowired public RedeliveryPolicy myRedeliveryPolicy() { RedeliveryPolicy myRedeliveryPolicy= new RedeliveryPolicy(); myRedeliveryPolicy.setMaximumRedeliveries(2); myRedeliveryPolicy.setMaximumRedeliveryDelay(2000); return myRedeliveryPolicy; } @Bean @Autowired public JmsComponent jms(IJMSConnectionFactory cf) throws JMSException { JmsComponent jmsComponent = new JmsComponent(); jmsComponent.setConfiguration(jmsConfig(cf)); jmsComponent.setTransacted(false); return jmsComponent; } from("jms:queue:TestQueue?acknowledgementModeName=CLIENT_ACKNOWLEDGE") .unmarshal().json(JsonLibrary.Jackson, TestObject.class) .transacted() .processRef("myPersistInDBProcessor")
I expect camel to try redeliveries as per redelivery policy (working) but MQ should not redeliver.
- I expect my camel route to run in a single db transaction.
- I expect MQ broker to redeliver only when my java service crashes in middle of processing, so that I do not lose the message.