Splitting a message into fragments
The Splitter EIP provides you with a versatile mechanism for breaking a message down into smaller fragments and processing them individually.
This recipe will show you how to use the Splitter EIP, along with Camel's built-in Expression Languages, to easily slice up your messages.
Getting ready
The Java code for this recipe is located in the org.camelcookbook.splitjoin.split
package. The Spring XML files are located under src/main/resources/META-INF/spring
and prefixed with split
.
How to do it...
Inside your route, create a split
statement, whose first line is the split expression. The following code splits a message naturally, meaning that any message that is an array, Collection
, or Iterator
will have each element processed individually through the statements in the block, as through a loop:
<from uri="direct:in"/> <split> <simple>${body}</simple> <to uri="mock:split"/> </split>
Here, ${body}
...