/
Guide to Java DSL (Splitter)

Guide to Java DSL (Splitter)

In some scenarios, the messages that we are processing may contain multiple elements and each of these may need to be handled in a completely different manner. In these situations, we use the Splitter pattern to allow us to separate a message into different parts and route each one individually.

In the following example, we see the implementation of a Splitter pattern to break a single composite message into separate pieces with each containing data related to a single item.

 

Java DSL Example

In the following route, we are consuming messages from an inbound folder. As it is read, each file will then be separated into a new message using a tokenizer. It is based on line breaks (“\n”) and we split out each new message as we move thru the file content line by line.

from("file://inbound") .split(body().tokenize("\n")) .to("acct:orderLines");

 

We can also separate our messages based on streams using streaming mode:

.split(body().tokenize(",")).streaming().to("acct:parts");

 

Or, in all the prior examples the message splits are happening in sequence. We can also perform this in parallel by using the parallelProcessing option:

 

.split(body().tokenize(",")).streaming() .parallelProcessing().to("acct:parts");