You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ext2 <xu...@tongtech.com> on 2010/11/26 18:07:48 UTC

Re: Some questions of camel's jta transaction support(failed to try the nested transaction)


I have post the failure testCase as a JIRA:
https://issues.apache.org/activemq/browse/CAMEL-3371


Thanks Clause:
> Check the book as it has such an example, where you can decide that
> the inner should rollback, but the outer should still commit.
> Camel got some options for that, such as rollbackLocalOnly()

I have tried the books sample , but if I configured the inner transaction 's
route as rollbackOnlyLast(). the inner route's db process cannot be executed
at all;

(although my test case coding is not exactly as the book sample , because I
has no the book's example source code in hand, so I adapt a camel 2.4's
spring test case as the chapter 9.4 said)
from("direct:outer")
.policy(required)
.setBody(constant("Tiger in Action")).beanRef("bookService")
.to("direct:inner")
.setBody(constant("Elephant in Action")).beanRef("bookService");
from("direct:inner")
  .policy(requireNew)
  .onException(Exception.class).markRollbackOnlyLast().end()
  .setBody(constant("Donkey in Action")).beanRef("bookService")

In my test, if configure
.onException(Exception.class).markRollbackOnlyLast().end()
The bookService bean of inner route will nerver be executed at all;
I am using camel 2.4 to do the test;
===================================================================
By the way , let assume  the above problem doesn't occur, and all things
works well; there is still another problem.(This question is just in my
mind, and I haven't proved it because the above problem)

That's:
	When markRollbackOnlyLast() set, the inner route will be rollbacked
if exception occurs.  And the outer route should continue to execute and
commit;
	But the outer route's pipeline will stopped just after the inner
route return; because Exchanged returned by the inner-route takes a
exception and marked as handled(This is the RedeliveryErrorHandler 's
result);
	Until now it sound reasonable: inner throw exception, the outer
catch it and stop execute; 
	But the real problem is : In outer route, I have no other
reason-able means to clear the exception. And let's the outer route to
continue to execute;
 For example if I using try-catch in the outer route to catch the
inner-route's exception.  But the try-catch cannot works at all; because the
inner route's has marked the exception of Exchange as "handled";
	The only way I can take is writing code to directly change the
exchange's Exception or set Exchange's properties; But this is mysterious
for the camel's end-user;

Sender: Claus Ibsen [mailto:claus.ibsen@gmail.com] 
Time: 2010年11月26日 16:53
Receiver: users@camel.apache.org
Subject: Re: Some questions of camel's jta transaction support

Hi

Camel in Action chapter 9 really covers transaction and compensations
really well.


On Fri, Nov 26, 2010 at 6:06 AM, ext2 <xu...@tongtech.com> wrote:
> 1: Could the from-endpoint decide how to do the post-action  according to
> following  route's transaction result(rollback/commit)?
>
>  Fo example :
>        from().transacted().multicast().db1().db2();
>
>        from() will receive a external message. Db1, db2 will insert the
> message to different database; and a jta-transaction is controlling the
two
> database resource.
>        Now we wish the (from) external system's message will be delete
only
> when the both database operation succeed. If one of it failed, the other
> database will rollback, and the (from) external system's message will also
> be reserved;
>        If the the (from) external system is a transactional-resource, etc:
> jms or database, there will no problem;
>        But if the (from) external system is file(or some other, etc:
email,
> ftp), could the camel's file component can delete or reserve the file
> according to the result of jta-transaction?
>

The Camel file component support this as it will only delete/moved the
file if its successful processed.
It checks the Exchange if an exception was thrown or not.


> 2) When using multi jta transaction in one exchange, it must be separate
to
> different route using direct-endpoint; But if so, when transactions  is
> nested; and inner's exception occurs,how does the outer transaction deal
> with the exception? Outer transaction will ignore the exception and
commit,
> or treat it as exception and rollback?
>
>  let's take a example:
>        {a,{b,c}d}
> The route has 4 processor, now [a,.. ,d] belong to a jta transaction,
[b-c]
> belong to a new jta  transaction;
> Camel will ask for configure it as two route:
>        From().transacted(required).a().to("direct:x").d();
>        From("direct:x").transacted().b().c();
>
> So if b or c raise exception in the inner transaction's route, how does
the
> outer transaction do? Rollback or commit ?
>

Check the book as it has such an example, where you can decide that
the inner should rollback, but the outer should still commit.
Camel got some options for that, such as rollbackLocalOnly()

And also try out yourself to see what happens.


>
> 3)  If I using multi transaction in one exchange , must I separate the it
to
> diff route using direct-endpoint?
>        ...actually, I find a un-document ways to use the multi camel
> transaction, which need not separate route . That's just configure the
> camel's transaction as a policy.
>
>        A few month ago, I have ask the question. And the answer is the
> camel's 2.1 doesn't support configured policy. But now camel's 2.5 is
> published, could it support such a usage?
>
>
>
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/