简体   繁体   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

What would be equivalent xml for the below java DSL, please suggest以下 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");
}

} }

I tried using the below xml configuration, without using aggregator, but when i am enabling parallelprocessing, it is working sequentially.我尝试使用以下 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>

i would suggest the following change to the upper route "processOrder"我建议对上层路线“processOrder”进行以下更改

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

if you want to use your AggregationStrategy again, you could add strategyRef="yourBean" to the splitter如果您想再次使用您的 AggregationStrategy,您可以将strategyRef="yourBean"添加到拆分器

Finally i was able to get the equivalent java DSL to XML and its working as expected最后,我能够获得等效的 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.

相关问题 在Java DSL上使用Java和Spring代码的Apache Camel - Apache Camel with Java and Spring Code on Java DSL 在Apache Camel中,Java DSL与Spring DSL相比有什么优势? - What are the advantages of Java DSL over Spring DSL in Apache Camel? 将Apache Camel示例从Spring DSL转换为Java DSL - Translating Apache Camel example from Spring DSL to Java DSL 使用Splitter并行处理的骆驼路线中的交易 - Transactions in camel routes with Splitter parallel processing 如何在 Apache 的 Camel Spring DSL (XML) 路由中以简单语言调用 Java 方法中的正则表达式? - How to escape regex in Java methods call in simple language in Apache's Camel Spring DSL (XML) route? 调用apache骆驼spring dsl xml中的两个toD - To call two toD in apache camel spring dsl xml 将Apache Camel JSON数据格式从XML转换为Java DSL - Convert Apache Camel JSON data format from XML to Java DSL 处理完所有行后,Spring Integration Java DSL流拆分器/聚合器删除文件 - Spring Integration Java DSL flow Splitter/Aggregator delete file after processing all lines Camel Splitter 并行处理数组列表 - 并发访问问题 - Camel Splitter Parallel Processing Array List - Concurrency Access Issue 使用apache-camel在Java中使用Tab分隔符获取SQL记录并将其写入文本文件(Spring和XML DSL文件除外) - Getting SQL records and write into text file with tab separated delimeter in Java using apache-camel (except Spring and XML DSL file)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM