You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Martin Samuelsson <ca...@martsam.se> on 2011/03/04 14:42:58 UTC

catch Exception thrown by ScheduledPollConsumer

Scenario: We have built a custom samba-component backed by jcifs that
extends GenericFileComponent. The Consumer extends GenericFileConsumer,
meaning it's also a ScheduledPollConsumer. The Consumer is in this case
using a custom Strategy that extends DefaultPollingConsumerPollStrategy. The
Strategy's rollback-method will under some circumstances throw an Exception
(e.g. when the share is unavailable or the provided credentials are
incorrect)

The RouteBuilder's configure-method looks something like this:

public void configure() {
    //...
    errorHandler(loggingErrorHandler("Handling FAILED"));

    onException(Exception.class)
            .log(LoggingLevel.INFO, "Caught an exception.");

     from("ourCustomerEndpointUri")
                .log(LoggingLevel.INFO, "Processing ${file:name}...")
                .to("anotherCustomEndpointUri");
    //...
}

Question: How can we handle this Exception?  We need a way to "catch" this
Exception and invoke another route (at this time to produce some custom
logging). The above code doesn't produce anything in the log. I believe this
have something to do with the Exception being thrown before the Exchange is
created.

Thanks in advance,

Martin

Re: catch Exception thrown by ScheduledPollConsumer

Posted by Martin Samuelsson <ma...@martsam.se>.
Hi again,
I overlooked your additional reply. Thank you for the pointer, we will look
into it! We are still in the learning stages when it comes to working with
Camel "the right way".

Great news about the upcoming feature as well...

Regards,

Martin



On Fri, Mar 4, 2011 at 5:26 PM, Claus Ibsen <cl...@gmail.com> wrote:

> On Fri, Mar 4, 2011 at 4:44 PM, Martin Samuelsson
> <ca...@martsam.se> wrote:
> > Hi Claus and thank you for your reply!
> >
> > I was afraid of that. We will have to do some thinking on this one...
> >
>
> You can just have a route for these errors and send the exception to
> this route, eg using the direct component and the producer template.
>
> There is a JIRA ticket to add a new feature to allow consumer to catch
> their internal errors and send them outwards with the error so the
> Camel error handler can react.
>
> However nothing we plan in the short term. Maybe for Camel 3.0.
>
>
>
>
> >
> > On Fri, Mar 4, 2011 at 3:01 PM, Claus Ibsen <cl...@gmail.com>
> wrote:
> >
> >> Hi
> >>
> >> The error handling in the route DSL only applies for messages.
> >> eg when an Exchange has been created by the consumer and successfully
> >> passed on to the Camel routing engine.
> >> At that point the routing error handler applies.
> >>
> >> The Camel in Action book covers this in section 5.1.2
> >>
> >> You have to deal with this error directly in your consumer.
> >>
> >>
> >>
> >> On Fri, Mar 4, 2011 at 2:42 PM,
> >> <ca...@martsam.se> wrote:
> >> > Scenario: We have built a custom samba-component backed by jcifs that
> >> > extends GenericFileComponent. The Consumer extends
> GenericFileConsumer,
> >> > meaning it's also a ScheduledPollConsumer. The Consumer is in this
> case
> >> > using a custom Strategy that extends
> DefaultPollingConsumerPollStrategy.
> >> The
> >> > Strategy's rollback-method will under some circumstances throw an
> >> Exception
> >> > (e.g. when the share is unavailable or the provided credentials are
> >> > incorrect)
> >> >
> >> > The RouteBuilder's configure-method looks something like this:
> >> >
> >> > public void configure() {
> >> >    //...
> >> >    errorHandler(loggingErrorHandler("Handling FAILED"));
> >> >
> >> >    onException(Exception.class)
> >> >            .log(LoggingLevel.INFO, "Caught an exception.");
> >> >
> >> >     from("ourCustomerEndpointUri")
> >> >                .log(LoggingLevel.INFO, "Processing ${file:name}...")
> >> >                .to("anotherCustomEndpointUri");
> >> >    //...
> >> > }
> >> >
> >> > Question: How can we handle this Exception?  We need a way to "catch"
> >> this
> >> > Exception and invoke another route (at this time to produce some
> custom
> >> > logging). The above code doesn't produce anything in the log. I
> believe
> >> this
> >> > have something to do with the Exception being thrown before the
> Exchange
> >> is
> >> > created.
> >> >
> >> > Thanks in advance,
> >> >
> >> > Martin
> >> >
> >>
> >>
> >>
> >> --
> >> 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/
> >>
> >
>
>
>
> --
> 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/
>

Re: catch Exception thrown by ScheduledPollConsumer

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Mar 4, 2011 at 4:44 PM, Martin Samuelsson
<ca...@martsam.se> wrote:
> Hi Claus and thank you for your reply!
>
> I was afraid of that. We will have to do some thinking on this one...
>

You can just have a route for these errors and send the exception to
this route, eg using the direct component and the producer template.

There is a JIRA ticket to add a new feature to allow consumer to catch
their internal errors and send them outwards with the error so the
Camel error handler can react.

However nothing we plan in the short term. Maybe for Camel 3.0.




>
> On Fri, Mar 4, 2011 at 3:01 PM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> Hi
>>
>> The error handling in the route DSL only applies for messages.
>> eg when an Exchange has been created by the consumer and successfully
>> passed on to the Camel routing engine.
>> At that point the routing error handler applies.
>>
>> The Camel in Action book covers this in section 5.1.2
>>
>> You have to deal with this error directly in your consumer.
>>
>>
>>
>> On Fri, Mar 4, 2011 at 2:42 PM,
>> <ca...@martsam.se> wrote:
>> > Scenario: We have built a custom samba-component backed by jcifs that
>> > extends GenericFileComponent. The Consumer extends GenericFileConsumer,
>> > meaning it's also a ScheduledPollConsumer. The Consumer is in this case
>> > using a custom Strategy that extends DefaultPollingConsumerPollStrategy.
>> The
>> > Strategy's rollback-method will under some circumstances throw an
>> Exception
>> > (e.g. when the share is unavailable or the provided credentials are
>> > incorrect)
>> >
>> > The RouteBuilder's configure-method looks something like this:
>> >
>> > public void configure() {
>> >    //...
>> >    errorHandler(loggingErrorHandler("Handling FAILED"));
>> >
>> >    onException(Exception.class)
>> >            .log(LoggingLevel.INFO, "Caught an exception.");
>> >
>> >     from("ourCustomerEndpointUri")
>> >                .log(LoggingLevel.INFO, "Processing ${file:name}...")
>> >                .to("anotherCustomEndpointUri");
>> >    //...
>> > }
>> >
>> > Question: How can we handle this Exception?  We need a way to "catch"
>> this
>> > Exception and invoke another route (at this time to produce some custom
>> > logging). The above code doesn't produce anything in the log. I believe
>> this
>> > have something to do with the Exception being thrown before the Exchange
>> is
>> > created.
>> >
>> > Thanks in advance,
>> >
>> > Martin
>> >
>>
>>
>>
>> --
>> 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/
>>
>



-- 
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/

Re: catch Exception thrown by ScheduledPollConsumer

Posted by Martin Samuelsson <ca...@martsam.se>.
Hi Claus and thank you for your reply!

I was afraid of that. We will have to do some thinking on this one...


On Fri, Mar 4, 2011 at 3:01 PM, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> The error handling in the route DSL only applies for messages.
> eg when an Exchange has been created by the consumer and successfully
> passed on to the Camel routing engine.
> At that point the routing error handler applies.
>
> The Camel in Action book covers this in section 5.1.2
>
> You have to deal with this error directly in your consumer.
>
>
>
> On Fri, Mar 4, 2011 at 2:42 PM,
> <ca...@martsam.se> wrote:
> > Scenario: We have built a custom samba-component backed by jcifs that
> > extends GenericFileComponent. The Consumer extends GenericFileConsumer,
> > meaning it's also a ScheduledPollConsumer. The Consumer is in this case
> > using a custom Strategy that extends DefaultPollingConsumerPollStrategy.
> The
> > Strategy's rollback-method will under some circumstances throw an
> Exception
> > (e.g. when the share is unavailable or the provided credentials are
> > incorrect)
> >
> > The RouteBuilder's configure-method looks something like this:
> >
> > public void configure() {
> >    //...
> >    errorHandler(loggingErrorHandler("Handling FAILED"));
> >
> >    onException(Exception.class)
> >            .log(LoggingLevel.INFO, "Caught an exception.");
> >
> >     from("ourCustomerEndpointUri")
> >                .log(LoggingLevel.INFO, "Processing ${file:name}...")
> >                .to("anotherCustomEndpointUri");
> >    //...
> > }
> >
> > Question: How can we handle this Exception?  We need a way to "catch"
> this
> > Exception and invoke another route (at this time to produce some custom
> > logging). The above code doesn't produce anything in the log. I believe
> this
> > have something to do with the Exception being thrown before the Exchange
> is
> > created.
> >
> > Thanks in advance,
> >
> > Martin
> >
>
>
>
> --
> 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/
>

Re: catch Exception thrown by ScheduledPollConsumer

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

The error handling in the route DSL only applies for messages.
eg when an Exchange has been created by the consumer and successfully
passed on to the Camel routing engine.
At that point the routing error handler applies.

The Camel in Action book covers this in section 5.1.2

You have to deal with this error directly in your consumer.



On Fri, Mar 4, 2011 at 2:42 PM, Martin Samuelsson
<ca...@martsam.se> wrote:
> Scenario: We have built a custom samba-component backed by jcifs that
> extends GenericFileComponent. The Consumer extends GenericFileConsumer,
> meaning it's also a ScheduledPollConsumer. The Consumer is in this case
> using a custom Strategy that extends DefaultPollingConsumerPollStrategy. The
> Strategy's rollback-method will under some circumstances throw an Exception
> (e.g. when the share is unavailable or the provided credentials are
> incorrect)
>
> The RouteBuilder's configure-method looks something like this:
>
> public void configure() {
>    //...
>    errorHandler(loggingErrorHandler("Handling FAILED"));
>
>    onException(Exception.class)
>            .log(LoggingLevel.INFO, "Caught an exception.");
>
>     from("ourCustomerEndpointUri")
>                .log(LoggingLevel.INFO, "Processing ${file:name}...")
>                .to("anotherCustomEndpointUri");
>    //...
> }
>
> Question: How can we handle this Exception?  We need a way to "catch" this
> Exception and invoke another route (at this time to produce some custom
> logging). The above code doesn't produce anything in the log. I believe this
> have something to do with the Exception being thrown before the Exchange is
> created.
>
> Thanks in advance,
>
> Martin
>



-- 
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/