Integration / Apache Camel Interview Questions
What is the Exchange in Camel — in-message, out-message, headers, and properties?
The Exchange is the message-passing container that travels through an entire route. When a consumer endpoint receives input, Camel wraps it in an Exchange and passes that object through every Processor. Everything a Processor needs — payload, metadata, and context — is accessed through the Exchange.
- In-message (exchange.getIn()): The current message with body, headers, and attachments. Processors read and write to this.
- Out-message (exchange.getOut()): The reply in InOut exchanges. In Camel 3.x writing to getOut() is discouraged because it creates a fresh Message and silently drops all headers set by prior processors.
- Headers: A Map<String, Object> on the current message. Components auto-populate keys like CamelFileName and JMSMessageID.
- Properties: Exchange-wide key-value pairs that persist across EIP steps like split() or aggregate().
- ExchangePattern: InOnly (fire-and-forget) or InOut (request-reply).
- Exception: Captured via exchange.getException() when a Processor throws.
from("direct:start")
.process(exchange -> {
String body = exchange.getIn().getBody(String.class);
exchange.getIn().setHeader("processedBy", "OrderProcessor");
exchange.setProperty("orderId", "ORD-1234"); // survives split
exchange.getIn().setBody(body.toUpperCase());
});
More Related questions...