Camel DSL - 在不同的路径中重用通过 Blueprint DSL 定义的转换逻辑

Camel DSL - Reuse transformation logic defined via Blueprint DSL in different routes

我想在不同的骆驼路线中重用蓝图 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>

这完美地重用了转换逻辑。但是由于直接同步 'calls' 路由不再独立。此外,我现在只有一个生产者速度变慢,因为不会发生转换消息的并行传递(这也是我不想将所有内容合并到一个路由中的原因)。

那么我怎样才能充分利用这两种方法 - 重用转换的定义并保持路由独立?预先感谢您的想法。

您可以在 java class 中提取转换逻辑,并将 java class 作为 spring 原型 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 方法调用,因此您可以从每个路由同时调用路由,它只是使用调用线程。

因此,您将转换器逻辑分离到路由中并使用直接调用它的做法是一个很好的解决方案。