MuleESB / Apache Camel Interview Questions
How does onException work in Camel and how do you configure retry, redelivery, and backoff?
onException(ExceptionClass.class) defines per-exception handling rules that override the route error handler for matched exception types. It must be declared BEFORE the from() in the RouteBuilder (in the configure() method). Multiple onException() clauses can coexist; Camel matches the closest superclass.
public void configure() {
// Per-exception handling
onException(IOException.class)
.maximumRedeliveries(5)
.redeliveryDelay(2000)
.backOffMultiplier(2.0)
.maximumRedeliveryDelay(30000) // cap at 30s
.retryAttemptedLogLevel(LoggingLevel.WARN)
.handled(true) // swallow the exception
.to("jms:queue:io-errors");
onException(ValidationException.class)
.handled(true) // mark Exchange as handled
.transform(exceptionMessage()) // body = exception message text
.to("direct:sendBadRequestResponse");
from("jms:queue:orders")
.to("http://payment-service/pay");
}Key configuration points: handled(true) marks the exception as consumed so Camel does not re-throw it; continued(true) marks it handled AND continues routing the original message; useOriginalMessage() restores the original body before sending to the DLQ. Exponential backoff is configured with backOffMultiplier() + maximumRedeliveryDelay(). For Camel Spring Boot, configure these via application.properties: camel.springboot.default-error-handler.maximum-redeliveries=3.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
