Dear All, I would like to discuss/have some advice on the following: Functional requirement: In case an error occurs in our route while while processing a message from ActiveMQ queue. We want the message to return back to the queue and the route to stop working.
Technically we think we need a combination of Transaction, onException handeling and a way to stop the route from further processing/running. This results in the following code: Camel transaction/activemq related configuration: <bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent"> <property name="transacted" value="true"/> <property name="transactionManager" ref="txManager"/> <property name="connectionFactory" ref="jmsConnectionFactory"/> </bean> <bean id="txManager" class="org.springframework.jms.connection.JmsTransactionManager"> <property name="connectionFactory" ref="jmsConnectionFactory" /> </bean> <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616"/> </bean> <bean id="txPolicy" class="org.apache.camel.spring.spi.SpringTransactionPolicy"> <property name="transactionManager" ref="txManager"/> <property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/> </bean> //stop the route in the onException onException(IOException.class) .process(new Processor() { Thread stopRouteInAnotherThread; @Override public void process(final Exchange exchange) throws Exception { // stopRouteInAnotherThread this route using a thread that will stopRouteInAnotherThread // this route gracefully while we are still running if (stopRouteInAnotherThread == null) { stopRouteInAnotherThread = new Thread() { @Override public void run() { try { exchange.getContext().stopRoute("poc-transaction"); } catch (Exception e) { // ignore } } }; } // start the thread that stops this route stopRouteInAnotherThread.start(); } }) .maximumRedeliveries(0) .handled(true); Simple Route: from("jms:queue:myQueueStart") .routeId("poc-transaction") .transacted(TX_POLICY_SPRING_BEAN) .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { throw new IOException("test"); } }).to("jms:queue:myQueueEnd"); The route is stopped though we expected the message not to be dequeue'd but it is dequeue'd. Does anyone know how to achieve this? Cheers, Praan -- View this message in context: http://camel.465427.n5.nabble.com/Transactions-Error-Stop-route-tp5723438.html Sent from the Camel - Users mailing list archive at Nabble.com.