我有一个骆驼应用程序,可以为多个帐户创建CSV提取。这是一个高级流程:
以下是骆驼路线:
from("{{setting.job.scheduling}}")
.log("JDS Reporting quartz job triggered")
.split().method(AccountService.class,"getAccounts").parallelProcessing(true) //for each account run the extract job
.to(ROUTE_URI);
from(ROUTE_URI).id(ROUTE_NAME)
.log("Running JDS job processor")
.to("bean:jobProcessor?method=process"); //create the job and kick off the reportProcessor
from("direct:reportProcessor").id(ROUTE_NAME)
.multicast().parallelProcessing(true).aggregationStrategy(new MultiCastAggregation())
.to("bean:inventoryProcessor?method=process") //query 1
.to("bean:productProcessor?method=process") //query 2
.end()
.log("Processing complete for jobId: ${header.jobId}, inventoryLoad:${property."+Constants.INVENTORY_LOAD_DONE +"} && productLoad:${property."+Constants.PRODUCT_LOAD_DONE + "}")
.choice()
.when(simple("${exchangeProperty."+Constants.INVENTORY_LOAD_DONE +"} == true && ${exchangeProperty."+Constants.PRODUCT_LOAD_DONE + "} == true" ))
.log("Processing complete for jobId: ${header.jobId}")
.to("direct:loadDBToFile")
.endChoice()
.end();
我的问题是关于步骤3中的聚合行为以及如何将多播聚合相关联。我已经注意到,有时会为两个不同的作业和重叠调用aggregationStrategy,这会导致问题。有什么方法可以通过id关联multicast()吗?
谢谢。
MultiCastAggregation的代码:
@Slf4j
public class MultiCastAggregation implements AggregationStrategy {
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
if (oldExchange == null) {
return newExchange;
} else {
if (StringUtils.equals(oldExchange.getIn().getBody(String.class), newExchange.getIn().getBody(String.class))) {
if (BooleanUtils.isTrue(oldExchange.getProperty(Constants.INVENTORY_LOAD_DONE, Boolean.class))
|| BooleanUtils.isTrue(newExchange.getProperty(Constants.INVENTORY_LOAD_DONE, Boolean.class))
&& BooleanUtils.isTrue((oldExchange.getProperty(Constants.PRODUCT_LOAD_DONE, Boolean.class))
|| BooleanUtils.isTrue(newExchange.getProperty(Constants.PRODUCT_LOAD_DONE, Boolean.class)))) {
oldExchange.setProperty(Constants.INVENTORY_LOAD_DONE, true);
oldExchange.setProperty(Constants.PRODUCT_LOAD_DONE, true);
}
} else {
log.error("Exchanges are for different JOBS!!!");
}
return oldExchange;
}
}
}