骆驼组播聚合与相关表达

时间:2019-01-13 23:14:40

标签: apache-camel

我有一个骆驼应用程序,可以为多个帐户创建CSV提取。这是一个高级流程:

  1. 石英计划作业启动了整个过程
  2. 加载所有帐户,并为每个帐户运行一个提取数据的作业(使用parallelProcessing)。
  3. 提取过程运行2个并发查询(使用多播/聚合器),这些查询已加载到内存数据库中
  4. 提取并创建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;
        }
    }
}

0 个答案:

没有答案