Integration / Apache Camel Interview Questions
How does the Dead Letter Channel work and how do you configure error handling in Camel?
The Dead Letter Channel (DLC) is a default error handler that retries failed exchanges a configurable number of times and, on exhaustion, routes the Exchange to a designated dead-letter endpoint. It prevents message loss when downstream systems are temporarily unavailable.
// Configure Dead Letter Channel on the RouteBuilder:
public class MyRoutes extends RouteBuilder {
@Override
public void configure() {
errorHandler(deadLetterChannel("jms:queue:DLQ")
.maximumRedeliveries(3)
.redeliveryDelay(1000) // 1s initial delay
.backOffMultiplier(2.0) // doubles: 1s, 2s, 4s
.retryAttemptedLogLevel(LoggingLevel.WARN)
.logExhausted(true)
.useOriginalMessage()); // send original msg, not transformed
from("jms:queue:orders")
.to("http://payment-service/pay");
}
}When all retries are exhausted, Camel adds an exception header (CamelExceptionCaught) to the Exchange before routing to the DLQ. useOriginalMessage() ensures the pristine inbound message reaches the DLQ, not a partially transformed version. The DLC can be scoped at route level (inside configure()) or globally (in a parent class). For per-exception handling, combine with onException().
More Related questions...