2016-04-20 147 views
-1

我是骆驼新手,我想以这样的方式编写骆驼路由,如果上层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
<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> 
       <simple>${in.body} == 'hi'</simple> 
       <to uri="direct:nextRoute" /> 
      </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>