使用Aggregator xml的Apache Camel-spring拆分器并行处理不像Java DSL那样工作
以下JavaDSL的等效xml是什么,请建议使用Aggregator xml的Apache Camel-spring拆分器并行处理不像Java DSL那样工作,java,apache-camel,Java,Apache Camel,以下JavaDSL的等效xml是什么,请建议 public class OrderRouter1 extends RouteBuilder { @Override public void configure() throws Exception { from("direct:processOrder") .split(body().method("getItems"), new OrderItemStrategy()) .parallelProces
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>
${body}
我建议对上层路线“processOrder”进行以下更改
${body.getItems}
如果您想再次使用聚合策略,您可以将
strategyRef=“yourBean”
添加到拆分器中最后,我能够获得与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>
${body.getItems}
${body.getType}=='Book'
谢谢Japu,是的,我可以添加它并进行检查,但我的问题是xml配置,我需要让它像java dsl一样并行工作。你应该试试,我认为它是按顺序拆分的,因为你没有调用getItems()
方法,因此您尝试分割整个身体-这可能是不可分割的,因此作为isYes传递。我试图查看文档,了解如何用xml编写文档,但无法获得正确的链接进行跟踪或阅读。@MadhusudhanGRevankar在完成上述更改后可能值得一看,但它仍然按顺序运行${body.getItems}
<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>