Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
SortSort can be used to sort a message. Imagine you consume text files and before processing each file you want to be sure the content is sorted. Sort will by default sort the body using a default comparator that handles numeric values or uses the string representation. You can provide your own comparator, and even an expression to return the value to be sorted. Sort requires the value returned from the expression evaluation is convertible to Options
Using from Java DSLIn the route below it will read the file content and tokenize by line breaks so each line can be sorted. from("file://inbox").sort(body().tokenize("\n")).to("bean:MyServiceBean.processLine"); You can pass in your own comparator as a 2nd argument: from("file://inbox").sort(body().tokenize("\n"), new MyReverseComparator()).to("bean:MyServiceBean.processLine"); Using from Spring DSLIn the route below it will read the file content and tokenize by line breaks so each line can be sorted. Camel 2.7 or better <route> <from uri="file://inbox"/> <sort> <simple>body</simple> </sort> <beanRef ref="myServiceBean" method="processLine"/> </route> Camel 2.6 or older <route> <from uri="file://inbox"/> <sort> <expression> <simple>body</simple> </expression> </sort> <beanRef ref="myServiceBean" method="processLine"/> </route> And to use our own comparator we can refer to it as a spring bean: Camel 2.7 or better <route> <from uri="file://inbox"/> <sort comparatorRef="myReverseComparator"> <simple>body</simple> </sort> <beanRef ref="MyServiceBean" method="processLine"/> </route> <bean id="myReverseComparator" class="com.mycompany.MyReverseComparator"/> Camel 2.6 or older <route> <from uri="file://inbox"/> <sort comparatorRef="myReverseComparator"> <expression> <simple>body</simple> </expression> </sort> <beanRef ref="MyServiceBean" method="processLine"/> </route> <bean id="myReverseComparator" class="com.mycompany.MyReverseComparator"/> Besides Using This PatternIf you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out. |