javaapache-camelspring-camel

How to execute an action in onException block before onRedelivery in camel?


I have an onException block in a camel route. It looks like this:

...
.onException(SomeException.class)
.maximumRedeliveries(3)
.redeliveryDelay(5000)
.onRedelivery(e -> {log()})
.retryAttemptedLogLevel(WARN)
.process(e -> {log()})
.handled(true)
...

The problem is that the redeliveries are executed before the process. I would like to do something before retry. Is that possible?


Solution

  • Based on the requirement in the comment to perform action immediately after exception. you can use .onExceptionOccurred() processor, which executes immediately after exception, whereas onRedelivery() executes before retry. You can refer docs for more info.

    ...
    .onException(SomeException.class)
    .onExceptionOccurred(e -> {log()})
    .maximumRedeliveries(3)
    .redeliveryDelay(5000)
    .onRedelivery(e -> {log()})
    .retryAttemptedLogLevel(WARN)
    .process(e -> {log()})
    .handled(true);
    ...