How can you sort the content of the message?


Use a special filter, a Message Translator, between other filters to sort the content of the message.


The Sort eip supports 0 options, which are listed below.

Name Description Default Type


Sets the description of this node.



Whether to disable this EIP from the route during build time. Once an EIP has been disabled then it cannot be enabled later at runtime.




Required Optional expression to sort by something else than the message body.



Sets the comparator to use for sorting.


Exchange properties

The Sort eip has no exchange properties.

How sorting works

Sort will by default sort the message body using a default Comparator that handles numeric values or uses the String representation.

You can also configure a custom Comparator to control the sorting.

An Expression can also be used, which performs the sorting, and returns the sorted message body. The value returned from the Expression must be convertible to java.util.List as this is required by the JDK sort operation.

Using Sort EIP

Imagine you consume text files and before processing each file, you want to be sure the content is sorted.

In the route below, it will read the file content and tokenize by line breaks so each line can be sorted.


You can pass in your own comparator as a second argument:

    .sort(body().tokenize("\n"), new MyReverseComparator())

In the route below, it will read the file content and tokenize by line breaks so each line can be sorted. In XML, you use the Tokenize language as shown:

  <from uri="file:inbox"/>
  <to uri="bean:myServiceBean.processLine"/>

And to use our own Comparator we do as follows:

  <from uri="file:inbox"/>
  <sort comparator="#class:com.mycompany.MyReverseComparator">
  <beanRef ref="MyServiceBean" method="processLine"/>

Notice how we use <simple>${body}</simple> in the example above to tell Sort EIP that it should use the message body for sorting. This is needed when you use a custom Comparator.