You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Ignat <iz...@gmail.com> on 2012/04/16 12:58:16 UTC

Error handling and invoking certain logic unconditionally

Hi All,

I need to solve following scenario with camel:

While message is being processed in route, I need to record certain
information based on content being processed. At the end of processing this
information have to be written to a storage (as a KPI event), clean-up
executed regardless of success / failure of message.
During route processing errors with remote components are handled by error
handler which uses JMS-based retry mechanism.

So far I was able to implement what I need with mixture of onCompletion
elements per route and custom error handler.

Unfortunately, I do have problem with behavior of onCompletion - it is
asynchronous, which makes integration tests quite tough (e.g. I can not rely
on order of events being generated, clean-up  / event writing logic did not
finish when pipeline is 'complete').

My option would be that onCompletion section would be executed on the same
thread that process pipeline and producer used to post message to pipeline
won't return until both logic within pipeline and onCompletion completes.

During my struggle with this scenario I've also tried try / finally logic,
unfortunately to find that try / finally completely disables error handler
(and since I used finally-only clause exception itself was not handled and
error handler was not called).

It is possible that this is just a mis-behavior of 2.4.0, then I will try
upgrading to more recent one.

Thanks in advance.



--
View this message in context: http://camel.465427.n5.nabble.com/Error-handling-and-invoking-certain-logic-unconditionally-tp5643480p5643480.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Error handling and invoking certain logic unconditionally

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, May 15, 2012 at 5:47 PM, Ignat <iz...@gmail.com> wrote:
> Thanks, Claus.
>
> For some reason I saw your reply just now (and did not receive any e-mails
> from nabble, which is strange).
>
> Is there a way to attach unit of work synchronization code in Spring DSL ?
>
> This would be real help!
>

No you need to use the Java API for that.

I logged a JIRA ticket to allow to configure the onCompletion to run sync
https://issues.apache.org/jira/browse/CAMEL-5286

> --
> View this message in context: http://camel.465427.n5.nabble.com/Error-handling-and-invoking-certain-logic-unconditionally-tp5643480p5710159.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Error handling and invoking certain logic unconditionally

Posted by Ignat <iz...@gmail.com>.
Thanks, Claus.

For some reason I saw your reply just now (and did not receive any e-mails
from nabble, which is strange).

Is there a way to attach unit of work synchronization code in Spring DSL ?

This would be real help!

--
View this message in context: http://camel.465427.n5.nabble.com/Error-handling-and-invoking-certain-logic-unconditionally-tp5643480p5710159.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Error handling and invoking certain logic unconditionally

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Apr 16, 2012 at 12:58 PM, Ignat <iz...@gmail.com> wrote:
> Hi All,
>
> I need to solve following scenario with camel:
>
> While message is being processed in route, I need to record certain
> information based on content being processed. At the end of processing this
> information have to be written to a storage (as a KPI event), clean-up
> executed regardless of success / failure of message.
> During route processing errors with remote components are handled by error
> handler which uses JMS-based retry mechanism.
>
> So far I was able to implement what I need with mixture of onCompletion
> elements per route and custom error handler.
>
> Unfortunately, I do have problem with behavior of onCompletion - it is
> asynchronous, which makes integration tests quite tough (e.g. I can not rely
> on order of events being generated, clean-up  / event writing logic did not
> finish when pipeline is 'complete').
>
> My option would be that onCompletion section would be executed on the same
> thread that process pipeline and producer used to post message to pipeline
> won't return until both logic within pipeline and onCompletion completes.
>
> During my struggle with this scenario I've also tried try / finally logic,
> unfortunately to find that try / finally completely disables error handler
> (and since I used finally-only clause exception itself was not handled and
> error handler was not called).
>
> It is possible that this is just a mis-behavior of 2.4.0, then I will try
> upgrading to more recent one.
>

You can use the API on Exchange to add a on completion (Its called
synchronization).
You may have to use the getUnitOfWork API to get to that point. The
2.4 release is rather old.
If you add using that API then its synchronous.

If you got the Camel in Action book, then see chapter 9, section 9.5
which cover this.

> Thanks in advance.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Error-handling-and-invoking-certain-logic-unconditionally-tp5643480p5643480.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/