【问题标题】:Camel DSL - Reuse transformation logic defined via Blueprint DSL in different routesCamel DSL - 在不同的路由中重用通过 Blueprint DSL 定义的转换逻辑
【发布时间】:2017-02-17 06:41:33
【问题描述】:

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

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

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

【问题讨论】:

    标签: apache-camel blueprint-osgi


    【解决方案1】:

    直接这样是不正确的,它就像一个java方法调用,所以你可以从每个路由并发调用路由,它只是使用调用线程。

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

    【讨论】:

      【解决方案2】:

      您可以在 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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-05-10
        • 1970-01-01
        • 1970-01-01
        • 2020-07-15
        • 2014-10-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多