【问题标题】:Apache Camel spring splitter parallel processing with aggregrator xml is not working as like of Java DSL使用聚合器 xml 的 Apache Camel spring splitter 并行处理不像 Java DSL 那样工作
【发布时间】:2020-04-23 13:21:38
【问题描述】:

以下java DSL的等效xml是什么,请建议

 public class OrderRouter1 extends RouteBuilder {

@Override
public void configure() throws Exception {

    from("direct:processOrder")
        .split(body().method("getItems"), new OrderItemStrategy())
        .parallelProcessing()
        .to("direct:processItem")
     .end();


    from("direct:processItem")
        .choice()
            .when(body().method("getType").isEqualTo("Book"))
                .to("bean:itemService?method=processBook").
            otherwise()
                .to("bean:itemService?method=processPhone");
}

}

我尝试使用以下 xml 配置,但不使用聚合器,但是当我启用并行处理时,它会按顺序工作。

 <camelContext id="orderCtx" xmlns="http://camel.apache.org/schema/spring">
   <route>
        <from uri="direct:processOrder" />
        <split parallelProcessing="true">
        <simple>${body}</simple>
            <to uri="direct:processItem" />
        </split>

    </route>

    <route>
        <from uri="direct:processItem" />
            <bean beanType="com.apache.camel.aggregrator.ItemSvc" method="processBook"/>
            <bean beanType="com.apache.camel.aggregrator.ItemSvc" method="processPhone"/>
        </route>


</camelContext>

【问题讨论】:

    标签: java apache-camel


    【解决方案1】:

    我建议对上面的路线“processOrder”进行以下更改

    <split parallelProcessing="true">
        <simple>${body.getItems}</simple>
        <to uri="direct:processItem" />
    </split>
    

    如果您想再次使用 AggregationStrategy,可以将 strategyRef="yourBean" 添加到拆分器

    【讨论】:

    • 谢谢 Japu,是的,我可以添加它并检查,但我的问题是 xml 配置我需要让它像 java dsl 并行工作一样工作
    • 你应该尝试一下,我认为它是连续分裂,因为你没有在 Spring-Camelcontext 中调用 getItems() 方法,因此你试图分裂整个身体 - 这可能不是可拆分,因此按原样传递
    • 是的。我试图查看文档我们如何在 xml 中编写它,但无法获得正确的链接来关注或阅读。
    • @MadhusudhanGRevankar 也许值得一看 camel.apache.org/simple.html#Simple-OGNLexpressionsupport
    • 经过上述修改后,仍按顺序运行 ${body.getItems}
    【解决方案2】:

    最后我能够得到与 XML 等效的 java DSL 并按预期工作

    <bean id="orderItemStrategy" class="com.apache.camel.aggregrator.OrderItemStrategy" />
    <bean id="itemService" class="com.apache.camel.aggregrator.ItemSvc" />
    <camelContext id="orderCtx" xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="direct:processOrder" />
            <split parallelProcessing="true" strategyRef="orderItemStrategy">
                <simple>${body.getItems}</simple>
                <to uri="direct:processItem" />
            </split>
        </route>
        <route>
            <from uri="direct:processItem" />
             <choice>
            <when>
                <simple>${body.getType} == 'Book'</simple>
               <to uri="bean:itemService?method=processBook" />
            </when>
             <otherwise>
               <to uri="bean:itemService?method=processPhone" />
            </otherwise>
        </choice>
        </route>
    </camelContext>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多