Reputation: 13585
How can I implement following Predicate Example given in Spring DSL:
Predicate isWidget = header("type").isEqualTo("widget");
from("jms:queue:order")
.choice()
.when(isWidget).to("bean:widgetOrder")
.when(isWombat).to("bean:wombatOrder")
.otherwise()
.to("bean:miscOrder")
.end();
Upvotes: 8
Views: 9576
Reputation: 1
IF the objective is to make use of a Predicate in Spring XML DSL then this would be more appropriate -
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camel:camelContext trace="true">
<camel:route>
<camel:from uri="jms:queue:order" />
<camel:filter>
<camel:method ref="myPredicate" />
<to uri="bean:widgetOrder"/>
</camel:filter>
</camel:route>
</camel:camelContext>
<bean id="myPredicate" class="MyPredicate"/>
</beans>
Upvotes: 0
Reputation: 61
The required simple element (see accepted answer) is
<simple>${header.type} == 'widget'</simple>
Notice how the field expression is surrounded by ${} followed by OGNL syntax for comparison, which is not part of the field expression itself.
Upvotes: 6
Reputation: 4653
Like this:
<route>
<from uri="jms:queue:order"/>
<choice>
<when>
<simple>${header.type} == 'widget'</simple>
<to uri="bean:widgetOrder"/>
</when>
<when>
<simple>${header.type} == 'wombat'</simple>
<to uri="bean:wombatOrder"/>
</when>
<otherwise>
<to uri="bean:miscOrder"/>
</otherwise>
</choice>
</route>
Upvotes: 6