Using a Java method as a Predicate
Camel makes it very easy to call out to some existing Java code to act as a predicate when you are using an Enterprise Integration Pattern (EIP) such as Content Based Router or Filter. Any EIPs that require a Camel Predicate can use the Bean Expression Language to call any Java method that evaluates to a boolean
value. Remember that a Camel Predicate is any Camel Expression that evaluates to a boolean
value (true
or false
). This allows you to integrate complex decision making from your existing Java code into your routing logic.
This recipe shows you how to use any of your Java methods that returns a boolean
value wherever Camel expects a predicate.
Getting ready
The Java code for this recipe is located in the org.camelcookbook.extend.predicate
package. The Spring XML files are located under src/main/resources/META-INF/spring
and prefixed with predicate
.
How to do it...
Given an existing Java method that evaluates to a boolean
value, such as:
public class MyPredicate...