Apache camel 如何无限制地聚合交易所

Apache camel 如何无限制地聚合交易所,apache-camel,restrictions,aggregator,filesplitting,Apache Camel,Restrictions,Aggregator,Filesplitting,我们有目前的情况。我使用ApacheCamel,为小型交换拆分大文件(使用拆分器,见下文)并验证它们。然后我需要聚合消息,但我使用聚合器,它需要设置完成大小或其他。我可以在不设置限制的情况下从当前文档中删除所有交换吗 我的路线: from("file:data?noop=true?move={{package.success}}&moveFailed={{package.failed}}") .transacted() .

我们有目前的情况。我使用ApacheCamel,为小型交换拆分大文件(使用拆分器,见下文)并验证它们。然后我需要聚合消息,但我使用聚合器,它需要设置完成大小或其他。我可以在不设置限制的情况下从当前文档中删除所有交换吗

我的路线:

 from("file:data?noop=true?move={{package.success}}&moveFailed={{package.failed}}")
                .transacted()
                .split(ExpressionBuilder.beanExpression(new InvoiceIteratorFactory(), "createIterator"))
                .streaming()
                .process(new ValidatorProcessor())
                .choice()
                .when(new Predicate() {
                    @Override
                    public boolean matches(Exchange exchange) {
                        return exchange.getContext().getProperty(ValidatorProcessor.STATE_PROPERTY).equals(ValidatorProcessor.STATE_SUCCESS);
                    }
                })
                .to("jpa:/...")
                .otherwise()
                .aggregate(body(String.class), new MyAggregationStrategy()).completionSize(????)
                .to("smtps://smtp.gmail.com?username={{remote.e-mail}}&password={{remote.password}}");

为了设置聚合器,我使用它来设置交换次数或时间,但我不知道会有多少交换。

所以骆驼中的拆分器EIP在每次完成交换拆分时都会生成一个名为
camelspittcomplete
的头。此标头是一个布尔值

我要做的是在聚合器中使用
completionPredicate()
,而不是
completionSize()
。因此,只要该标头为true,它就会完成聚合:

from("file:data?noop=true?move={{package.success}}&moveFailed={{package.failed}}")
    .transacted()
    .split(ExpressionBuilder.beanExpression(new InvoiceIteratorFactory(), "createIterator"))
    .streaming()
    .process(new ValidatorProcessor())
    .choice()
    .when(new Predicate() {
                @Override
                public boolean matches(Exchange exchange) {
                    return exchange.getContext().getProperty(ValidatorProcessor.STATE_PROPERTY).equals(ValidatorProcessor.STATE_SUCCESS);
                }
            })
     .to("jpa:/...")
     .otherwise()
     .aggregate(body(String.class), new MyAggregationStrategy()).completionPredicate(header("CamelSplitComplete") == true)
     .to("smtps://smtp.gmail.com?username={{remote.e-mail}}&password={{remote.password}}");

我希望这就是你想要的。

我建议你放慢速度,写一个较长的问题,说明你想做什么以及为什么。谢谢,我会试试的。但我还有一个问题。正如您在route中所看到的,应用程序读取文件,将解析良好的实体保存到DB,如果有错误,它会将带有这些错误的消息聚合起来,然后发送到电子邮件。我有这样的问题,如何回滚在解析当前文件期间提交给DB的所有实体?