Integration / Apache Camel Interview Questions
What are the error handling strategies in Camel (DefaultErrorHandler, DeadLetterChannel, TransactionErrorHandler)?
Camel provides three built-in error handler implementations, configurable per-route via errorHandler(...):
| Handler | Retries | Use case |
|---|---|---|
| DefaultErrorHandler | Configurable (default 0) | Non-transactional routes that log failures. |
| DeadLetterChannel | Configurable (default 0) | Routes needing guaranteed delivery to a DLQ after retries exhausted. |
| TransactionErrorHandler | Driven by transaction manager | JMS/JDBC transactional routes requiring rollback on failure. |
| NoErrorHandler | None | Testing or scenarios where all error handling is done manually. |
// Default (no-DLQ): log on failure
errorHandler(defaultErrorHandler()
.maximumRedeliveries(2)
.redeliveryDelay(500));
// Dead Letter Channel
errorHandler(deadLetterChannel("jms:queue:DLQ")
.maximumRedeliveries(3)
.backOffMultiplier(2.0)
.useOriginalMessage());
// Transactional error handler
errorHandler(transactionErrorHandler(transactionManager)
.maximumRedeliveries(3)
.redeliveryDelay(1000));Error handlers can be scoped globally (in the parent RouteBuilder configure() or in a shared class) or per-route (placed at the start of a specific configure() method). Global scope applies to all routes defined in that builder. For per-exception handling, use onException() on top of any error handler to add targeted retry/routing logic for specific exception types.
More Related questions...