Circuit Breaker for asynchronous channel along with Dead Letter Channel

244 Views Asked by At

I have a requirement to use circuit breaker along with a Dead Letter Channel (DLC). The errored out messages should go to DLC. The other messages should not be consumed while the circuit is open. Right now I have implemented like below:

public void configure() throws Exception {
// @formatter:off

    int threshold = 2;
    long failureWindow = 30000;
    long halfOpenAfter = 120000;
    RoutePolicy routePolicy = 
      new ThrottlingExceptionRoutePolicy(threshold, failureWindow, halfOpenAfter, null);

    errorHandler(deadLetterChannel("seda:errorQueue").
               useOriginalMessage().maximumRedeliveries(3).redeliveryDelay(1000));



    from("timer://myTimer?period=5s")
    .routeId("InputFolderToTestSedaRoute")
    .setBody(exchangeProperty(Exchange.TIMER_FIRED_TIME))
    .convertBodyTo(String.class)
    .to("seda://testSeda")
    .log("**** Input data published to  testSeda - ${body}***** :")
    ;

    from("seda://testSeda")
    .routeId("TestSedaToOutputFolderRoute")
    .routePolicy(routePolicy)
    .to("file://{{outputFolder}}?autoCreate=false&fileName=TimerFile-${exchangeProperty.CamelTimerCounter}")
    ;

    //Error Handling route!

    from("seda:errorQueue")
    .routeId("ErrorHandlingRoute")
    .log("***** error body: ${body} *****")
    .to("file://{{errorFolder}}?fileName=TimerFile-${exchangeProperty.CamelTimerCounter}.txt")
    .log("***** Exception Caught: ${exception} *****")
    ;

    // @formatter:on

}

The problem is that this won't work as expected if DLC is enabled. But if I comment the line starting with "errorHandler(deadLetterChannel()" it will work - means the above code will work ONLY with default error handler.

My question is - I want the error messages to go to error Queue AND I want the circuit breaker enabled. Is there any way? Thank you very much for your time.

1

There are 1 best solutions below

2
On

I resolved the issue. Instead of the DLC, I just added the following:

onException(GenericFileOperationFailedException.class).handled(false).to("seda:errorQueue");

That solved the issue.