对于下面的java DSL,x等价的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>
答案 0 :(得分:1)
我建议对上面的路线进行以下更改&#34; processOrder&#34;
<split parallelProcessing="true">
<simple>${body.getItems}</simple>
<to uri="direct:processItem" />
</split>
如果您想再次使用AggregationStrategy,可以将strategyRef="yourBean"
添加到拆分器
答案 1 :(得分:0)
最后,我能够获得与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>