骆驼时/对于activemq和seda

时间:2015-07-17 20:59:58

标签: apache-camel

我有一条路线,我想计算"来自"是activemq或其他东西。我找到了replaceFromWith,但它似乎只用于测试。我尝试使用驼峰的选择何时/以及来自activemq""和#34;来自seda",但这些错误作为无效语法。我正在寻找能够做到以下事情的事情:

<route id="doPost">     
    <choice>
        <when>
            <groovy>exchange.getIn().getHeader("sometest") != null</groovy>                 
            <from uri="activemq:doPost?..."/>
        </when>
        <otherwise>                                
            <from uri="seda:doPost?....."/>
        </otherwise>
    </choice>   

提前致谢,感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您无法根据交易所动态选择消费者,在使用<from .../>代码消费之前,交易所不会存在。

相反,您可以为每个消费者构建一条路线,规范化您从不同类型的消费者那里收到的交换,并将它们转发到一个共同的路线进行处理。

<route id="activemqConsumerRoute">
  <from uri="activemq:doPost?..."/>
  <!-- normalize the exchange to be understandable by the next route -->
  <to uri="direct:commonProcessingRoute" />
</route>

<route id="sedaConsumerRoute">
  <from uri="seda:doPost?....."/>
  <!-- normalize the exchange to be understandable by the next route -->
  <to uri="direct:commonProcessingRoute" />
</route>

<route id="commonProccessingRoute">
  <from uri="direct:commonProcessingRoute" />
  <!-- whatever business logic you have -->
</route>