You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Charles Moulliard <cm...@gmail.com> on 2009/07/03 09:50:23 UTC

Camel Transaction and errorHandlerRef question

Hi,

1) Best place of  TransactionErrorHandlerBuilder

I would like to know where is the bast place to put the reference of the
TransactionErrorHandlerBuilder in a transactional route ? At the level of
the route OR transacted ?

    <bean id="PROPAGATION_REQUIRED"
class="org.apache.camel.spring.spi.SpringTransactionPolicy">
        <property name="transactionManager">
            <osgi:reference
interface="org.springframework.transaction.PlatformTransactionManager"/>
        </property>
    </bean>

    <bean id="txErrorHandler"
class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder">
        <property name="springTransactionPolicy"
ref="PROPAGATION_REQUIRED"/>
    </bean>

    <camel:route errorHandlerRef="txErrorHandler"> // Here
            <camel:from ref="queueQuickFixInEndpoint" />
            <camel:convertBodyTo type="quickfix.Message" />
            <camel:transacted ref="PROPAGATION_REQUIRED"/> // OR HERE
            <camel:bean ref="serviceHelper" method="createNotification" />
            <camel:bean ref="serviceHelper" method="generateError" />
            <camel:to ref="directNotificationEndpoint" />
        </camel:route>

Regards,

Charles Moulliard
Senior Enterprise Architect
Apache Camel Committer

*****************************
blog : http://cmoulliard.blogspot.com

Re: Camel Transaction and errorHandlerRef question

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Jul 3, 2009 at 9:50 AM, Charles Moulliard<cm...@gmail.com> wrote:
> Hi,
>
> 1) Best place of  TransactionErrorHandlerBuilder
>
> I would like to know where is the bast place to put the reference of the
> TransactionErrorHandlerBuilder in a transactional route ? At the level of
> the route OR transacted ?
>
>    <bean id="PROPAGATION_REQUIRED"
> class="org.apache.camel.spring.spi.SpringTransactionPolicy">
>        <property name="transactionManager">
>            <osgi:reference
> interface="org.springframework.transaction.PlatformTransactionManager"/>
>        </property>
>    </bean>
>
>    <bean id="txErrorHandler"
> class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder">
>        <property name="springTransactionPolicy"
> ref="PROPAGATION_REQUIRED"/>
>    </bean>
>
>    <camel:route errorHandlerRef="txErrorHandler"> // Here
>            <camel:from ref="queueQuickFixInEndpoint" />
>            <camel:convertBodyTo type="quickfix.Message" />
>            <camel:transacted ref="PROPAGATION_REQUIRED"/> // OR HERE
>            <camel:bean ref="serviceHelper" method="createNotification" />
>            <camel:bean ref="serviceHelper" method="generateError" />
>            <camel:to ref="directNotificationEndpoint" />
>        </camel:route>
>
> Regards,
>
> Charles Moulliard
> Senior Enterprise Architect
> Apache Camel Committer
>
> *****************************
> blog : http://cmoulliard.blogspot.com
>

Using <transacted> allows you to do convention over configuration. As
it can auto discover the spring TX manager itself.
That allows you to reduce the configuration to a bare minimum.

You *always* need to declare a route as transacted by setting the
   <transacted/>
otherwise the route is not transacted from a Camel point of view as it
uses this to weave in a TX interceptor.

It also makes reading the route easier as you can see its transacted.
And it should be the first step in the route.

So this is fine
    <camel:route errorHandlerRef="txErrorHandler">
            <camel:from ref="queueQuickFixInEndpoint" />
            <camel:transacted ref="PROPAGATION_REQUIRED"/>
            <camel:convertBodyTo type="quickfix.Message" />
            <camel:bean ref="serviceHelper" method="createNotification" />
            <camel:bean ref="serviceHelper" method="generateError" />
            <camel:to ref="directNotificationEndpoint" />
        </camel:route>

But <transacted> can also auto discover the error handler itself so
you can loose the errorHandlerRef if you want. But if you have
multiple error handlers then Camel does not know which to pick. So
what you do is good.






-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus