Integration / Apache Camel Interview Questions
How does the Splitter EIP work and when would you use it?
The Splitter breaks a single message into multiple sub-messages, processes each independently, and optionally aggregates the results. It is used when a single inbound message contains a collection of items (a CSV line batch, a JSON array, an XML node list) that must be processed individually.
// Split a CSV line batch into individual records:
from("file:/in?noop=true")
.unmarshal().csv()
.split(body()) // splits List into individual rows
.parallelProcessing() // optional: process sub-messages in parallel
.streaming() // optional: do not buffer the whole list
.to("jms:queue:order-items")
.end(); // end of splitter sub-route
// Split XML using XPath:
from("direct:xmlOrders")
.split(xpath("//order"))
.to("direct:processOrder");Each sub-message gets a copy of the original headers plus Camel-generated metadata: CamelSplitIndex (0-based position), CamelSplitSize (total count), and CamelSplitComplete (true on last item). The sub-route between split() and end() is a full processing pipeline. Use streaming() for large collections to avoid loading everything into memory.
More Related questions...