Search code examples
apache-camelspring-camel

Execute task after reaching threshold for maximumRedeliveries in Camel


I have implemented a retry functionality in my code using camel retry. It will retry a maximum of five times.

onException(Exception.class)
    .maximumRedeliveries(5)
    .retryAttemptedLogLevel(LoggingLevel.WARN)
    .backOffMultiplier(5)
    .maximumRedeliveryDelay(5)
    .useExponentialBackOff();

Now I want to call a custom method if the threshold has been reached instead of throwing an exception. How can I achieve this?


Solution

  • You can set the handled-flagto true and then call your custom bean.

    onException(Exception.class)
        .maximumRedeliveries(5)
        .retryAttemptedLogLevel(LoggingLevel.WARN)
        .backOffMultiplier(5)
        .maximumRedeliveryDelay(5)
        .useExponentialBackOff()
        .handled(true)
        .to("bean:myCustomBean");