job.answiz.com
  • 1
Votes
name
name Punditsdkoslkdosdkoskdo

How to Error hander and load balancer in Camel

I am using apache camel and I want a route that would utilise a Dead Letter channel and Circuit Breaker.

If I have something like:

errorHandler(deadLetterChannel(destination))

from("direct:start").loadBalance()
            .circuitBreaker(2, 1000L, MyCustomException.class)
                .to("mock:result");

What happens is that the handler moves the message to the DLQ and the circuit breaker never moves to an open state.

My goal is to somehow keep the DLQ channel behaviour, but use the CB as well, which would eventually open and reject messages (from propagating to the destionation or to the normal processing).

Thanks!

I'm more of a doTry...doCatch guy myself :-)

You can enclose your loadBalance EIP inside a doTry...doCatch and treat the final exception in there as you see fit. Same for the intermediate exceptions: use doTry...doCatch inside your from("direct:foo") and from("direct:bar") routes and operate on the caught exceptions as you like. Of course, don't forget to rethrow them afterwards.

  • 0
Reply Report