如何在Spring DSL中实现以下谓词示例given:
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();
答案 0 :(得分:6)
所需的简单元素(见accepted answer)是
<simple>${header.type} == 'widget'</simple>
注意字段表达式如何被$ {}包围,后跟OGNL语法进行比较,这不是字段表达式本身的一部分。
答案 1 :(得分:5)
像这样:
<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>
答案 2 :(得分:0)
如果目标是在Spring XML DSL中使用谓词,那么这会更合适-
<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>