1
votes

I wanted to apply re-deliver and use Dead Letter Channel. So found this very useful apache-camel FAQ link. I followed the steps as mentioned in this website.

I added a little more logic, the code is available in github .

Basically, as per the FAQ, we have to split the routes, such that(as mentioned in the FAQ) the camel can handle any exception in the sub route. Here is the code (Camel Route):

    @Override
public void configure() throws Exception {
    errorHandler(deadLetterChannel("mock:error")
            .logExhaustedMessageBody(true)
            .logExhausted(true)
            .logRetryStackTrace(true)
            .maximumRedeliveries(3)
            .redeliveryDelay(1000)
            .backOffMultiplier(2)
            .useOriginalMessage()
            .useExponentialBackOff());

    from("direct:start")
    .log("Dump incoming body: " + body())
    .to("direct:sub")
    .end();

    from("direct:sub")
    .errorHandler(noErrorHandler())
    .process(new SubRouteProcessor())
    .log("Dump incoming body: "+ body())
    .process(new NewSubRouteProcessor())
    .transform(body().append("Modified Data !"))
    .to("mock:result");
}

I wrote a simple unit test, to trigger the exception, hence the redeliver code is executed.

Now the difficulty/problem: The expected behavior is to do only 3 redeliver attempts, with 1000 millis delay and ExponentialBackOff.

However, the Test runs forever, keeps on doing the re-delivery with exponential delay. If I remove/comment the 2 processor calls, the code does run fine, means on exception, it does only 3 retries.

Could you please help to understand, 1) what is wrong in this code/route? 2) what is causing code to run forever? 3) why removing these processors, it works,retry happens for said number of times only?

I just want - when ever the "direct:sub" throws "exception", the control goes back to "direct:start", re-try processing message from a certain point.

Thank you !!

1
Can you please share the code for your Processors? It seems to me that you have identified the problem correctly, it should lie within the Processors.Ramin Arabbagheri
@RaminArabbagheri i already shared github location, can you access it?rak22
Yes I can, I didn't see the link first time round! May I ask why you are setting the body on the Out message? I don't see why you should need anything but In() message i.e exchange.getIn().setBody(body)Ramin Arabbagheri
Just creating a new Message Object. And yes I agree, i could use In() as well. camel.apache.org/using-getin-or-getout-methods-on-exchange.htmlrak22

1 Answers

1
votes

I checked out your code and simply by changing getOut to getIn in both of your processors, the test passes.

Edit: My suspicion from the beginning was that your processors were somehow overriding the headers Camel set in order to do a certain amount of redelivery. In your case:

CamelRedelivered=true, CamelRedeliveryCounter=1, CamelRedeliveryMaxCounter=3

The header CamelRedeliveryCounter was not incremented when you were setting the Body on the getOut exchange. In my mind, it should and this is a bug; but maybe it is working as designed? Maybe @claus-ibsen could help with that.

Hope this helps.

R.