-
1. Re: custom load balancer / failover component handling an exception...
e0richt Mar 13, 2013 2:35 PM (in response to e0richt)public class ErrorHandler extends LoadBalancerSupport {
. . private static final Logger logger = LoggerFactory.getLogger
. . (ErrorHandler.class);
. static int NUM_PROCESSORS = 2;
. int which = 0;
. public boolean process(Exchange exchange, AsyncCallback callback) {
. String body = exchange.getIn().getBody(String.class);
. logger.info("ErrorHandler: got message:"+ body);
. System.out.println("ErrorHandler: got message:"+ body);
. try {
. logger.info("ErrorHandler: going to:"which" processor");
. System.out.println("ErrorHandler: going to:"which" processor");
. getProcessors().get(which).process(exchange);
. } catch (Throwable e) {
. logger.info("ErrorHandler: caught an exception:"+e.getMessage());
. System.out.println("ErrorHandler: caught an exception:"+e.getMessage());
. which = (++which) % NUM_PROCESSORS;
. exchange.setException(e);
. }
. callback.done(true);
. return true;
. }
Edited by: e0richt on Mar 13, 2013 6:30 PM
-
load-balancer-example.rtf 2.1 KB
-
-
2. Re: custom load balancer / failover component handling an exception...
davsclaus Mar 13, 2013 2:30 PM (in response to e0richt)If there is an exception its stored on the exchange when the process method returns. So you need to check for that
Exception cause = exchange.getException(); if (cause != null) { ... }
-
3. Re: custom load balancer / failover component handling an exception...
e0richt Mar 13, 2013 2:40 PM (in response to davsclaus)ok, I will try that...
However, I am curious then why the example code (which I basically copied from the fuse documentation) has the try... catch code at all then?
also interestingly enough if you use the exception handler option for the route you can't seem to get the exception through that mechanism (x = ex.getException()...)
you actually have to use a header property to get the exception...
-
4. Re: custom load balancer / failover component handling an exception...
e0richt Mar 13, 2013 10:00 PM (in response to davsclaus)yup, that suggestion works...
kinda weird how one has to use ex.getException() for some things and use the header property for others...
-
5. Re: custom load balancer / failover component handling an exception...
davsclaus Mar 14, 2013 3:35 AM (in response to e0richt)If you have a copy of Camel in Action book then read chapter 5. Its explained there.
-
6. Re: custom load balancer / failover component handling an exception...
davsclaus Mar 14, 2013 3:36 AM (in response to e0richt)No its not. The header has a caused exception that an error handler has handled / dealt with.
The getException is when an exception just occurred and hasn't been handled by an error handler.