You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by WPk <wa...@gmail.com> on 2013/10/29 20:06:09 UTC

Camel transacted route

Hello,

We have set up a Camel route using transacted(). The route comprises
multiple JDBC transactions and we required some kind of transaction
management to be implemented, we decided to use transacted().

The route looks like this :


from("direct:updatebookauthor").tracing()
                        .transacted("PROPAGATION_REQUIRED")
                        .convertBodyTo(BookShelf.class)
                        .enrich("direct:getbookauthor", new
BookShelfEnrichAggregationStrategy(Action.UPDATE))
                        .process(new DroolsCommandTransformer<Work>("work",
Work.class)).to("drools:node/ksession")                     
                       
.transform().simple("${body.getValue('work').newContainer}")
                        .bean(bookShelfRepo, "update")
                        .choice()
                                .when(body().isNotNull())
                                        .process(new BookCatgProcessor())
                                        .choice()
                                                .when(body().isNotNull())
                                                        .bean(bookShelfRepo,
"updateBookDept")
                                                        .bean(bookShelfRepo,
"updateBookCategory")
                                        .end()
                                        .choice()
                                                 .when(body().isNull())
                                                         .process(new
BookShelfProcessor())
                                        .end()
                        .end()
                        .onException(Exception.class).markRollbackOnly();

Spring Transaction Policy Bean is created as follows:

        private void setupTransactionPolicy() {
                try{
                        Context initialContext = new InitialContext();
                        Context envContext = (Context)
initialContext.lookup("java:comp/env");
                        DataSource ds = (DataSource)
envContext.lookup("jdbc/us/wm/TraitsDs");
                        DataSourceTransactionManager dsm = new
org.springframework.jdbc.datasource.DataSourceTransactionManager(ds);
                        SpringTransactionPolicy stp = new
org.apache.camel.spring.spi.SpringTransactionPolicy(dsm);
                       
stp.setPropagationBehaviorName("PROPAGATION_REQUIRED");
                        TraitHierarchyRoutes.PROPAGATION_REQUIRED_BEAN =
stp;
 
                }catch(Exception e){
                        throw new RuntimeException("Exception while setting
up spring transaction policy" + e);
                }
        }
 
Bean is bound to Camel Registry for referencing in the route.
 
                JndiRegistry registry =
(JndiRegistry)((PropertyPlaceholderDelegateRegistry)this.getContext().getRegistry()).getRegistry();
                registry.bind("PROPAGATION_REQUIRED",
PROPAGATION_REQUIRED_BEAN);

And the issue is that the Transaction Handling not happening and is rolling
back the transactions on exceptions.. We have tried with and with out
setting the auto commit property to true. Also, we have tried using the
transacted() alone with out onException&markRollBack. No luck. Please advice
!




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

Re: Camel transacted route

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I suggest to make a simpler use-case to see if you can get that
working, eg something that just do a  couple of JDBC inserts to see if
you can have it commit and rollback as expected with TX in a Camel
route.

eg is often to setup all that JDBC / DataSource / Spring TX stuff that
can be a bit tricky to get all pieces right.

And use as simple as possible Camel route, eg just from X to Y to Z etc.




On Fri, Nov 1, 2013 at 9:01 PM, WPk <wa...@gmail.com> wrote:
> Hi,
> Thanks for responding. The transactions are not committed even when there
> are no exceptions.. transacted() does not seem to do any job..
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-transacted-route-tp5742362p5742528.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Camel transacted route

Posted by WPk <wa...@gmail.com>.
Hi,
Thanks for responding. The transactions are not committed even when there
are no exceptions.. transacted() does not seem to do any job..





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

Re: Camel transacted route

Posted by Baris Acar <ba...@acar.org.uk>.
> the issue is that the Transaction Handling not happening and is rolling


back the transactions on exceptions.




What behaviour do you want/expect?




Rolling back on exception is a feature of using transactions. That's the behaviour  that's usually wanted.










—
Sent from Mailbox for iPhone

On Wed, Oct 30, 2013 at 2:11 AM, WPk <wa...@gmail.com> wrote:

> Hello,
> We have set up a Camel route using transacted(). The route comprises
> multiple JDBC transactions and we required some kind of transaction
> management to be implemented, we decided to use transacted().
> The route looks like this :
> from("direct:updatebookauthor").tracing()
>                         .transacted("PROPAGATION_REQUIRED")
>                         .convertBodyTo(BookShelf.class)
>                         .enrich("direct:getbookauthor", new
> BookShelfEnrichAggregationStrategy(Action.UPDATE))
>                         .process(new DroolsCommandTransformer<Work>("work",
> Work.class)).to("drools:node/ksession")                     
>                        
> .transform().simple("${body.getValue('work').newContainer}")
>                         .bean(bookShelfRepo, "update")
>                         .choice()
>                                 .when(body().isNotNull())
>                                         .process(new BookCatgProcessor())
>                                         .choice()
>                                                 .when(body().isNotNull())
>                                                         .bean(bookShelfRepo,
> "updateBookDept")
>                                                         .bean(bookShelfRepo,
> "updateBookCategory")
>                                         .end()
>                                         .choice()
>                                                  .when(body().isNull())
>                                                          .process(new
> BookShelfProcessor())
>                                         .end()
>                         .end()
>                         .onException(Exception.class).markRollbackOnly();
> Spring Transaction Policy Bean is created as follows:
>         private void setupTransactionPolicy() {
>                 try{
>                         Context initialContext = new InitialContext();
>                         Context envContext = (Context)
> initialContext.lookup("java:comp/env");
>                         DataSource ds = (DataSource)
> envContext.lookup("jdbc/us/wm/TraitsDs");
>                         DataSourceTransactionManager dsm = new
> org.springframework.jdbc.datasource.DataSourceTransactionManager(ds);
>                         SpringTransactionPolicy stp = new
> org.apache.camel.spring.spi.SpringTransactionPolicy(dsm);
>                        
> stp.setPropagationBehaviorName("PROPAGATION_REQUIRED");
>                         TraitHierarchyRoutes.PROPAGATION_REQUIRED_BEAN =
> stp;
>  
>                 }catch(Exception e){
>                         throw new RuntimeException("Exception while setting
> up spring transaction policy" + e);
>                 }
>         }
>  
> Bean is bound to Camel Registry for referencing in the route.
>  
>                 JndiRegistry registry =
> (JndiRegistry)((PropertyPlaceholderDelegateRegistry)this.getContext().getRegistry()).getRegistry();
>                 registry.bind("PROPAGATION_REQUIRED",
> PROPAGATION_REQUIRED_BEAN);
> And the issue is that the Transaction Handling not happening and is rolling
> back the transactions on exceptions.. We have tried with and with out
> setting the auto commit property to true. Also, we have tried using the
> transacted() alone with out onException&markRollBack. No luck. Please advice
> !
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-transacted-route-tp5742362.html
> Sent from the Camel - Users mailing list archive at Nabble.com.