Appendix B. Expressions and predicates
Expressions and predicates are built-in types in Camel that you’ve seen used throughout this book. They’re very versatile and are used in different places, but they’re most noticeable in the Camel routes. For example, predicates are used in the Message Filter and Content-Based Router EIPs. Expressions are used for computing correlation keys for the Aggregator EIP, and appendix A covered the Simple expression language, which is another testament to the versatility of expressions.
A Camel expression (org.apache.camel.Expression) is evaluated at runtime on the instance of Exchange that is under processing. You can use either standard or custom expressions.
The org.apache.camel.Expression interface is as follows:
The evaluate method uses generics to specify the desired return type.
Camel provides syntax sugar for working with expressions. Suppose you want to implement a route that can return a message consisting of “Hello” plus the input message. This can be done using the Message Translator EIP, which leverages an Expression to transform a message. With the help of the syntax sugar, you can use the fluent builder style in the Java DSL to express that you want to prepend “Hello” to the message body: