Okay we have got it working:

Transaction 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>

Sample Route with onException:
Note: make the camel route BundleContextAware (by implementing
BundleContextAware)

//act upon the (error) cause of the rollback
        onException(IOException.class)
                .process(new Processor() {
                    //create a new thread to stop the bundle.
                    //Stopping the route in the same 'running' thread
                    //might result in infinite wait
                    Thread stopRouteInAnotherThread = null;

                    @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 {
                                        Bundle bundle =
bundleContext.getBundle();
                                        bundle.stop();
                                    } catch (BundleException e) {
                                        LOG.error("Failed to stop bundle: "
+ e.getMessage());
                                    }
                                }
                            };
                        }

                        // start the thread that stops this route
                        stopRouteInAnotherThread.start();
                    }
                })
                .useOriginalMessage();

from("jms:queue:praan")
                .routeId("YOUR_ROUTE_ID")
                .transacted("txPolicy")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception
{
                        if
(exchange.getIn().getBody(String.class).contains("Deepika")) {
                            throw new IOException("test exception to break
route");
                        }
                    }
                }).to("jms:queue:praan_out");



--
View this message in context: 
http://camel.465427.n5.nabble.com/Transactions-Error-Stop-route-tp5723438p5723590.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to