繁体   English   中英

Apache Camel spring splitter 与聚合器 xml 的并行处理不像 Java DSL 那样工作

[英]Apache Camel spring splitter parallel processing with aggregrator xml is not working as like of Java DSL

以下 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>

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

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

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

最后,我能够获得等效的 Java DSL 到 XML 及其按预期工作

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM