我想在不同的骆驼路由中重复使用由蓝图DSL定义的转换步骤,但找不到如何实现这一目标。
让我们在这里举一个例子:
<camelContext id="jms-context" xmlns="http://camel.apache.org/schema/blueprint">
<route id="inputAqTest8">
<from id="_fromAqTest8" uri="aqTest8:queue:QUELOGENTRY"/>
<!-- some complicated transformation here -->
<to id="_to1" uri="umChannel:topic:Input"/>
</route>
<route id="inputAqTest12">
<from id="_fromAqTest12" uri="aqTest12:queue:QUEPOSTDATA"/>
<!-- some complicated transformation here -->
<to id="_to2" uri="umChannel:topic:Input"/>
</route>
</camelContext>
我已经通过将转换和交付到由直接组件连接的自己的路线进行了优化。
<camelContext id="jms-context" xmlns="http://camel.apache.org/schema/blueprint">
<route id="inputAqTest8">
<from id="_fromAqTest8" uri="aqTest8:queue:QUELOGENTRY"/>
<to id="_to1" uri="direct:process"/>
</route>
<route id="inputAqTest12">
<from id="_fromAqTest12" uri="aqTest12:queue:QUEPOSTDATA"/>
<to id="_to2" uri="direct:process"/>
</route>
<route id="process">
<from id="_from1" uri="direct:process"/>
<!-- some complicated transformation here -->
<to id="_to" uri="umChannel:topic:Input"/>
</route>
</camelContext>
这完美地重复了转换逻辑。但是,由于直接同步"呼叫"路线不再是独立的。另外,我现在只有一个生产者放慢脚步,因为可能会发生转换消息的平行传递(这也是我不想将全部合并为单个路线的原因)。
那么,如何在两种方法中都能获得最好的方式 - 重复使用转换的定义并使路线独立?预先感谢您的想法。
直接不正确,就像java方法调用一样,因此您可以同时从每个路线中调用路由,仅使用调用线程。
因此,将变压器逻辑分为路线并使用Direct调用是一个很好的解决方案。
您可以在Java类中提取转换逻辑,并将Java类作为弹簧原型bean,并在每个路由中使用该bean的实例。我很确定它将完成工作
<bean id="myBean" scope="pototype" class="com.my.org.MyComplexTransformation/>
<route id="inputAqTest8">
<from id="_fromAqTest8" uri="aqTest8:queue:QUELOGENTRY"/>
<bean ref="myBean"/>
<to id="_to1" uri="umChannel:topic:Input"/>
</route>
<route id="inputAqTest12">
<from id="_fromAqTest12" uri="aqTest12:queue:QUEPOSTDATA"/>
<bean ref="myBean"/>
<to id="_to2" uri="umChannel:topic:Input"/>
</route>