camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Kettelerij <richardkettele...@gmail.com>
Subject Re: Question about TransactionErrorHandlerBuilder
Date Sat, 14 May 2011 09:55:42 GMT
You need to use the SpringRouteBuilder instead of the plain Java
RouteBuilder. Instead of instantiating a TransactionErrorHandlerBuilder
yourself you can just use the DSL method to configure the
TransactionalErrorHandler. In that case Camel will also be able to perform a
lookup of your transaction manager.

So your route will be something like:

camel.addRoutes(new SpringRouteBuilder() {
                       public void configure() {
                               errorHandler(new LoggingErrorHandlerBuilder()
                                       .level(LoggingLevel.WARN));

                               // not transactional
                               from("amq:xxx")
                               .routeId("heartbeat-amq-to-wmq")
                               .startupOrder(1)
                               .onException(JMSException.class)
                               .handled(true)
                               .to("log:applogger?level=ERROR")
                               .end()
                               .to("wmq:xxx");

                               // transactional
                               from("wmq:yyy")
                               .routeId("data-wmq-to-amq")
                               .startupOrder(2)
                               .errorHandler(transactionErrorHandler()
                             .maximumRedeliveries(1)

                             .redeliveryDelay(1000)
                             .retryAttemptedLogLevel(LoggingLevel.WARN))
                               .transacted("wmqTxPolicy")
                               .to("amq:yyy");

                       }
               });

instantiating a TransactionErrorHandlerBuilder yourself

On Sat, May 14, 2011 at 10:40 AM, Hanson <hanson2010@gmail.com> wrote:

> The camel was configured as follows:
>
>                camel.addRoutes(new RouteBuilder() {
>                        public void configure() {
>                                errorHandler(new
> LoggingErrorHandlerBuilder()
>                                        .level(LoggingLevel.WARN));
>
>                                // not transactional
>                                from("amq:xxx")
>                                .routeId("heartbeat-amq-to-wmq")
>                                .startupOrder(1)
>                                .onException(JMSException.class)
>                                .handled(true)
>                                .to("log:applogger?level=ERROR")
>                                .end()
>                                .to("wmq:xxx");
>
>                                // transactional
>                                from("wmq:yyy")
>                                .routeId("data-wmq-to-amq")
>                                .startupOrder(2)
>                                .errorHandler(new
> TransactionErrorHandlerBuilder()
>                                        .maximumRedeliveries(1)
>                                        .redeliveryDelay(1000)
>
>  .retryAttemptedLogLevel(LoggingLevel.WARN))
>                                .transacted("wmqTxPolicy")
>                                .to("amq:yyy");
>
>                        }
>                });
>
> wmqTxPolicy was defined in spring:
>
>        <bean id="wmqTxPolicy"
> class="org.apache.camel.spring.spi.SpringTransactionPolicy">
>                <property name="transactionManager" ref="wmqTxManager"/>
>                <property name="propagationBehaviorName"
> value="PROPAGATION_REQUIRED"/>
>        </bean>
>        <bean id="wmqTxManager"
>
>  class="org.springframework.jms.connection.JmsTransactionManager">
>                <property name="connectionFactory"
> ref="wmqConnectionFactory" />
>        </bean>
>        ...
>
> The exception was:
> 2011-05-14 16:21:56,031 [main] INFO : Apache Camel 2.7.1
> (CamelContext:camel-1) is shutting down
> 2011-05-14 16:21:56,031 [main] INFO : Starting to graceful shutdown 0
> routes
> (timeout 300 seconds)
> 2011-05-14 16:21:56,046 [main] INFO : Graceful shutdown of 0 routes
> completed in 0 seconds
> 2011-05-14 16:21:56,046 [main] INFO : Shutting down with no inflight
> exchanges.
> 2011-05-14 16:21:56,046 [main] INFO : Uptime: 2.609 seconds
> 2011-05-14 16:21:56,046 [main] INFO : Apache Camel 2.7.1 (CamelContext:
> camel-1) is shutdown in 0.015 seconds
> 2011-05-14 16:21:56,046 [main] ERROR: Exception in AAA: Failed to create
> route data-wmq-to-amq at: >>> Policy[ref:wmqTxPolicy] <<< in route:
> Route[[From[wmq:YYY]] -> [Policy[ref:wmqTxPolicy... because of
> transactionTemplate must be specified on: TransactionErrorHandlerBuilder
> Unexpected exception org.apache.camel.FailedToCreateRouteException
> org.apache.camel.model.RouteDefinition.addRoutes 815
> org.apache.camel.model.RouteDefinition.addRoutes 165
> org.apache.camel.impl.DefaultCamelContext.startRoute 706
> org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions 1643
> org.apache.camel.impl.DefaultCamelContext.doStartCamel 1432
> org.apache.camel.impl.DefaultCamelContext.doStart 1336
> org.apache.camel.impl.ServiceSupport.start 67
> org.apache.camel.impl.ServiceSupport.start 54
> org.apache.camel.impl.DefaultCamelContext.start 1314
> ...
>
> How to add a transactionTemplate to TransactionErrorHandlerBuilder? Thanks
> in ad!
>
>
> -----
> ~Hanson
> Java for food, Python for fun
> http://hanson.appspot.com/
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Question-about-TransactionErrorHandlerBuilder-tp4395278p4395278.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message