我是骆驼的新手,我想写一条骆驼路线,如果上面的bean方法返回“hi”,那么我必须调用另一条路线。但这不会发生在下面的代码中。请让我知道解决方案。
这是我的代码:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
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
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="firstRoute">
<from uri="activemq:queue:test.queue" />
<doTry>
<to uri="bean:myBean?method=appendCamel(1,hell)" />
<log message="TEST LOG" />
<when>
<xpath>${in.body} = 'hi'</xpath>
<to uri="stream:out" />
</when>
<doCatch>
<exception>java.lang.Exception</exception>
</doCatch>
</doTry>
<to uri="stream:out" />
<to uri="bean:myBean?method=appendCamel2(34)" />
<to uri="stream:out" />
<to uri="direct:nextRoute" />
</route>
<route>
<from uri="direct:nextRoute" />
<to uri="stream:out" />
</route>
</camelContext>
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false" />
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="connectionFactory" />
</bean>
<bean id="myBean" class="Camel.CamelHelloWorldSid.MyBean" />
答案 0 :(得分:1)
您应该使用过滤器EIP:http://camel.apache.org/message-filter.html
<filter>
<simple>${in.body} == 'hi'</simple>
<to uri="direct:nextRoute" />
</filter>
如果你需要多个谓词,那么你需要使用基于内容的路由器:http://camel.apache.org/content-based-router.html(就像if ... elseif ... elseif ...在Java中的其他地方)
答案 1 :(得分:0)
{{1}}