Apache camel 驼峰DSL-在不同的路由中重用通过Blueprint DSL定义的转换逻辑
我想在不同的驼峰路线中重用blueprint DSL定义的转换步骤,但找不到如何实现这一点 让我们举一个例子:Apache camel 驼峰DSL-在不同的路由中重用通过Blueprint DSL定义的转换逻辑,apache-camel,blueprint-osgi,Apache Camel,Blueprint Osgi,我想在不同的驼峰路线中重用blueprint DSL定义的转换步骤,但找不到如何实现这一点 让我们举一个例子: <camelContext id="jms-context" xmlns="http://camel.apache.org/schema/blueprint"> <route id="inputAqTest8"> <from id="_fromAqTest8" uri="aqTest8:queue:QUELO
<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>
我已经通过将转换和交付移动到由direct组件连接的自己的路线来对此进行了优化
<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类中提取转换逻辑,并将该java类作为spring原型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>
您可以在java类中提取转换逻辑,将该java类作为spring原型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>
这对于direct是不正确的,它就像java方法调用,因此您可以从每个路由并发调用路由,它只是使用调用线程
因此,将转换器逻辑分离为一个路由并使用direct调用它是一个很好的解决方案。这对于direct是不正确的,它就像java方法调用一样,因此您可以从每个路由并发调用路由,它只是使用调用线程
所以,将变压器逻辑分离成一条路由并使用direct调用它是一个很好的解决方案