camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: AsyncProcessor implementation patterns
Date Thu, 19 Sep 2013 06:04:54 GMT
Hi

Have you seen this page
http://camel.apache.org/asynchronous-processing.html

And if you return false, then the you must call callback.done(false)
later when the other process comes back with the data, which you can
then store on the exchange, and then call the done(false) method to
signal to Camel to continue routing.

If you have a copy of Camel in Action, then chapter 10, section 10.6
dives into this.

On Wed, Sep 18, 2013 at 7:38 PM, fbarbat <fbarbat@gmail.com> wrote:
> Hi,
>
> I want to implement a custom AsyncProcessor so I can have more control on a
> custom Netty channel. Is the following pattern recommended?
>
> @Override
>         public boolean process(Exchange exchange, AsyncCallback callback) {
>                 try {
>                         //Do whatever sync preparations and async invocations, set the
exchange
> result and signal back
>
>                         // continue routing asynchronously
>                         return false;
>
>                 } catch (Exception e) {
>                         //If an excepction was thrown synchronously, handle it here,
do not throw
> it
>                         exchange.setException(e);
>                         callback.done(true);
>                         return true;
>                 }
>         }
>
> CamelInternalProcessor has this code:
>
>             // ----------------------------------------------------------
>             // CAMEL END USER - DEBUG ME HERE +++ START +++
>             // ----------------------------------------------------------
>             try {
>                 processor.process(exchange);
>             } catch (Throwable e) {
>                 exchange.setException(e);
>             }
>             // ----------------------------------------------------------
>             // CAMEL END USER - DEBUG ME HERE +++ END +++
>             // ----------------------------------------------------------
>
>             // ----------------------------------------------------------
>             // CAMEL END USER - DEBUG ME HERE +++ START +++
>             // ----------------------------------------------------------
>             if (LOG.isTraceEnabled()) {
>                 LOG.trace("Processing exchange for exchangeId: {} -> {}",
> exchange.getExchangeId(), exchange);
>             }
>             boolean sync = processor.process(exchange, async);
>             // ----------------------------------------------------------
>             // CAMEL END USER - DEBUG ME HERE +++ END +++
>             // ----------------------------------------------------------
>
> In the synchronous version, it uses a try catch. Why does this
> implementation not use a try-catch in the asynchronous version?
>
> Thanks!
>
> By the way, I've been posting a lot these days, thanks for your help! I
> really appreciate it. I'm having a hard time to use Eclipse on Camel source
> code projects. As soon as I could get over it, I would like to contribute.
> Thanks!
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/AsyncProcessor-implementation-patterns-tp5739773.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

Mime
View raw message