Guide to Sort (Message Transformation)

The sort pattern is used to sort the contents of a message body, assuming that the message body contains a list of items that can be sorted.

By default, the contents of the message are sorted using a default comparator that handles numeric values or strings. You can provide your own comparator and you can specify an expression that returns the list to be sorted (the expression must be convertible to java.util.List).

Java DSL example

This example will generate a list of items to sort by tokenizing on the line break character:

from("file://inbox").sort(body().tokenize("\n")).to("bean:MyServiceBean.processLine");

We can also pass our own comparator as the second argument:

from("file://inbox").sort(body().tokenize("\n"), new MyReverseComparator()).to("bean:MyServiceBean.processLine");

XML DSL Example

This example generates the list of items to sort by tokenizing on the line break character:

<route> <from uri="file://inbox"/> <sort> <simple>body</simple> </sort> <beanRef ref="myServiceBean" method="processLine"/> </route>

We can also pass our own comparator as a bean:

Sort Options

Name

Default Value

Description

Name

Default Value

Description

comparatorRef

 

Refers to a custom version of java.util.Comparator to use for sorting the message body. It will by default use a comparator which does a A..Z sorting.