You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Alex Anderson <al...@gmail.com> on 2012/02/15 15:09:32 UTC

Handling Endpoint failure

Hi,

I'm working on an Endpoint which has a background service keeping it alive.

When this service fails, I would like the associated Exception (or a
derived Exception) to propagate to Camel so that it can be dealt with.

In the application I am working on, the behaviour in this case would
be to destroy all routes associated with this Endpoint (usually it
will be two routes).

The service keep-alive is not associated with a Camel Exchange, so I
can't see how this fits into Camel's normal Error Handling.

Is there an obvious way to achieve what I want?

Thanks,

Alex

Re: Handling Endpoint failure

Posted by Alex Anderson <al...@frontlinesms.com>.
Hi Ashwin,

Thanks for your help on this.  I ended up solving this by creating an
Exchange with the Exception attached, like so:

The exception can be passed to a route in the Consumer like so:

       class MyConsumer { ...
              public void handleEndpointException(EndpointException ex) {
                      Exchange exchange = getEndpoint().createExchange();
                      exchange.setException(ex);
                      getProcessor().process(exchange);
              } ...

The exception can then be handled by an onException clause():

       ...route-definition...
       .onException(EndpointException)
                       .handled(true)
                       .beanRef("someService", "handleEndpointException")
                       .end()

And in someService, I have the following method:

       def handleEndpointException(Exchange ex) {
               EndpointException caughtException = (EndpointException)
ex.getProperty(Exchange.EXCEPTION_CAUGHT);
               ...
       }

Alex


On 15 February 2012 18:32, Ashwin Karpe <ak...@fusesource.com> wrote:
> Hi,
>
> Hmm, This goes to whether routes are kinda self-directed, i.e., inability to
> produce messages to a destination brings down the route itself...
>
> While perfectly do-able, provided the consumer endpoint provides a
> capability to do so via a flag/switch, I would rather not employ this
> strategy. It would drive system admins crazy if routes were suddenly coming
> down of their own accord and require them to make secondary checks to see
> what happened. Too much power & chaos!!!...
>
> Ideally, you might want to delegate the ability to bring down routes to
> another bean/service/entity that could be notified on Connect Exceptions and
> then have it bring down the necessary routes gracefully.
>
> In the absence of that doing it directly in the exception handling route
> would also do the trick, albeit only within the boundaries of the Camel
> Context in which the exception is caught...
>
> Cheers,
>
> Ashwin...
>
> -----
> ---------------------------------------------------------
> Ashwin Karpe
> Apache Camel Committer & Sr Principal Consultant
> FUSESource (a Progress Software Corporation subsidiary)
> http://fusesource.com
>
> Blog: http://opensourceknowledge.blogspot.com
> ---------------------------------------------------------
> --
> View this message in context: http://camel.465427.n5.nabble.com/Handling-Endpoint-failure-tp5486157p5486388.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Handling Endpoint failure

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

Hmm, This goes to whether routes are kinda self-directed, i.e., inability to
produce messages to a destination brings down the route itself... 

While perfectly do-able, provided the consumer endpoint provides a
capability to do so via a flag/switch, I would rather not employ this
strategy. It would drive system admins crazy if routes were suddenly coming
down of their own accord and require them to make secondary checks to see
what happened. Too much power & chaos!!!...

Ideally, you might want to delegate the ability to bring down routes to
another bean/service/entity that could be notified on Connect Exceptions and
then have it bring down the necessary routes gracefully.

In the absence of that doing it directly in the exception handling route
would also do the trick, albeit only within the boundaries of the Camel
Context in which the exception is caught...

Cheers,

Ashwin...

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
--
View this message in context: http://camel.465427.n5.nabble.com/Handling-Endpoint-failure-tp5486157p5486388.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Handling Endpoint failure

Posted by Alex Anderson <al...@frontlinesms.com>.
Hi Ashwin,

Thanks for the tip.

If I have access to the Consumer, can I just call
`consumer.getExceptionHandler().handleException(new
ConnectException(...))`?

Alex


On 15 February 2012 18:00, Ashwin Karpe <ak...@fusesource.com> wrote:
> Hi,
>
> Since the Camel endpoint has no way of knowing whether the service is up
> other than a ConnectException being thrown, you would need to trap this
> Exception and then do whatever you need to do through the Exception handling
> mechanism.
>
> You could set up a Processor in the exception handling route that brings
> down all the associated routes when it catches a ConnectException.
>
> Hope this helps.
>
> Cheers,
>
> Ashwin...
>
>
> -----
> ---------------------------------------------------------
> Ashwin Karpe
> Apache Camel Committer & Sr Principal Consultant
> FUSESource (a Progress Software Corporation subsidiary)
> http://fusesource.com
>
> Blog: http://opensourceknowledge.blogspot.com
> ---------------------------------------------------------
> --
> View this message in context: http://camel.465427.n5.nabble.com/Handling-Endpoint-failure-tp5486157p5486283.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Handling Endpoint failure

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

Since the Camel endpoint has no way of knowing whether the service is up
other than a ConnectException being thrown, you would need to trap this
Exception and then do whatever you need to do through the Exception handling
mechanism.

You could set up a Processor in the exception handling route that brings
down all the associated routes when it catches a ConnectException. 

Hope this helps.

Cheers,

Ashwin...


-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
--
View this message in context: http://camel.465427.n5.nabble.com/Handling-Endpoint-failure-tp5486157p5486283.html
Sent from the Camel - Users mailing list archive at Nabble.com.