Integration / Apache Camel Interview Questions
What is a Processor in Camel and how do you implement a custom Processor?
A Processor is the atomic unit of message manipulation in Camel — any class implementing org.apache.camel.Processor. Every EIP construct compiles to Processors chained in a Pipeline. A custom Processor gives direct access to the full Exchange: body, headers, properties, and exception state.
The interface declares one method:
public interface Processor {
void process(Exchange exchange) throws Exception;
}A custom Processor that validates an order and stamps an audit header:
public class OrderValidationProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
String body = exchange.getIn().getBody(String.class);
if (body == null || body.isBlank()) {
exchange.setException(new IllegalArgumentException("Empty payload"));
return;
}
exchange.getIn().setHeader("X-Validated-At",
java.time.Instant.now().toString());
exchange.getIn().setBody(body.trim());
}
}
from("jms:queue:raw-orders")
.process(new OrderValidationProcessor())
.to("jms:queue:valid-orders");
// Lambda shorthand:
from("direct:greet")
.process(e -> e.getIn().setBody("Hello " + e.getIn().getBody(String.class)));Processor vs Bean: Use Processor when you need direct Exchange-level access (headers, exceptions). Use .bean(MyBean.class) when the logic is pure business code — keeping domain classes free of Camel API imports and independently unit-testable.
More Related questions...