Hi

Just for the record. In Camel 2.0 we have improved the
TransactionErrorHandler to support the onException as well. So now you can
handle thrown exceptions for transacted routes as well.

A note though: Any of the redelivery stuff is of course not supports for
transacted routes. Redelivery is done by the transaction manager, eg from a
JMS broker, WebSphere TX or the likes.




Lin.Zhang wrote:
> 
> I tried to use DeadLetterChannel to add some redelivery delay when some
> exception occured. The problem I have now is if transaction is not used,
> the dlc works fine. But if in a transaction, the dlc just seems not work
> for there is no delay between redeliveries. I use ActiveMQ as the
> datasource and spring for transaction support. Can somebody tell me
> whether DLC can work in transactions? Here are my source files, Thanks.
> 
> [[aplicationContext.xml]]
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans";
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>        xmlns:camel="http://activemq.apache.org/camel/schema/spring";
>        xmlns:amq="http://activemq.apache.org/schema/core";
>        xsi:schemaLocation="
>         http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>         http://activemq.apache.org/camel/schema/spring
> http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
>         http://activemq.apache.org/schema/core
> http://activemq.apache.org/schema/core/activemq-core.xsd";>
> 
>       <camel:camelContext id="camel" />       
>       
>       <bean id="jmsConfig"
> class="org.apache.camel.component.jms.JmsConfiguration">
>               <property name="connectionFactory" ref="jmsConnectionFactory" />
>               <property name="transactionManager" ref="jmsTransactionManager" 
> /> 
>               <property name="transacted" value="true" />
>       </bean>
>       
>       <bean id="activemq" class="org.apache.camel.component.jms.JmsComponent">
>               <property name="configuration" ref="jmsConfig" />
>       </bean>
>       
>       <bean id="PROPAGATION_REQUIRED"
> class="org.springframework.transaction.support.TransactionTemplate">
>               <property name="transactionManager" ref="jmsTransactionManager" 
> />
>       </bean> 
>       
>       <bean id="PROPAGATION_NOT_SUPPORTED"
> class="org.springframework.transaction.support.TransactionTemplate">
>               <property name="transactionManager" 
> ref="jmsTransactionManager"/>
>               <property name="propagationBehaviorName"
> value="PROPAGATION_NOT_SUPPORTED"/>
>       </bean>
> 
>       <bean id="PROPAGATION_REQUIRES_NEW"
> class="org.springframework.transaction.support.TransactionTemplate">
>               <property name="transactionManager" 
> ref="jmsTransactionManager"/>
>               <property name="propagationBehaviorName"
> value="PROPAGATION_REQUIRES_NEW"/>
>       </bean> 
>               
>       <bean id="jmsTransactionManager"
> class="org.springframework.jms.connection.JmsTransactionManager">
>               <property name="connectionFactory" ref="jmsConnectionFactory" />
>       </bean>         
>       
>       <bean id="jmsConnectionFactory"
> class="org.apache.activemq.ActiveMQConnectionFactory" depends-on="broker">
>               <property name="brokerURL" value="tcp://localhost:61616" />
>       </bean>
>       
>       <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
>               <property name="config" value="/activemq.xml" />
>       </bean>
> </beans>
> 
> [[Main.java]]
> package com.abc.actxii;
> 
> import org.apache.camel.CamelContext;
> import org.apache.camel.CamelTemplate;
> import org.apache.camel.Exchange;
> import org.apache.camel.Processor;
> import org.apache.camel.spi.Policy;
> import org.apache.camel.spring.SpringCamelContext;
> import org.apache.camel.spring.SpringRouteBuilder;
> import org.apache.camel.spring.spi.SpringTransactionPolicy;
> import org.springframework.context.ApplicationContext;
> import org.springframework.context.support.ClassPathXmlApplicationContext;
> import org.springframework.transaction.support.TransactionTemplate;
> 
> public class Main {
> 
>       private static ApplicationContext springContext;
>       private static CamelContext camelContext;
>       private static CamelTemplate camelTemplate;
>       
>       public static void main(String[] args) throws Exception {
>               springContext = new
> ClassPathXmlApplicationContext("applicationContext.xml");
>               camelContext = getCamelContext(springContext);
>               
>               camelTemplate = getCamelTemplate(camelContext);
>               
>               camelContext.addRoutes(new SpringRouteBuilder() {
>                       @Override
>                       public void configure() throws Exception {
>                               Policy required = new
> SpringTransactionPolicy(bean(TransactionTemplate.class,
> "PROPAGATION_REQUIRED"));
>                                                                               
>                 
>                               from("activemq:com.abc.actxii.dest")
>                               
> .errorHandler(deadLetterChannel("file://failure").maximumRedeliveries(5).initialRedeliveryDelay(2500).maximumRedeliveryDelay(30000))
>                                       .policy(required)
>                                       .process(new Processor() {              
>                                               
>                                               public void process(Exchange 
> exchange) throws Exception {
>                                                       
> System.out.println("message = " +
> exchange.getIn().getBody().toString() + ", " + System.currentTimeMillis()
> );
>                                                       throw new 
> Exception("test");
>                                               }
>                                       }).to("file://success");
>                       }
>               });
>                               
>               camelTemplate.sendBody("activemq:com.stubhub.actxii.dest", 
> "Hello
> World");
>       }
> 
>       private static CamelTemplate getCamelTemplate(CamelContext camelContext)
> {
>               return new CamelTemplate(camelContext);
>       }
> 
>       private static SpringCamelContext getCamelContext(
>                       ApplicationContext springContext) {
>               return (SpringCamelContext)springContext.getBean("camel");
>       }
> 
> }
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Can-DeadLetterChannel-be-used-in-Transaction--tp19385266p22905715.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Reply via email to