MuleESB / 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.
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...
