문제

I'm new in working with Apache Camel. Could you help me with moving files? I have such route:

from("file:data?noop=true?move={{package.success}}&moveFailed={{package.failed}}")
                .split(ExpressionBuilder.beanExpression(new InvoiceIteratorFactory(), "createIterator"))
                .streaming()
                .process(new ValidatorProcessor())
                .choice()
                .when(new Predicate() {
                    @Override
                    public boolean matches(Exchange exchange) {
                        ..;
                    }
                })
                .to("jpa://...?consumer.transacted=true")
                .otherwise()
                .aggregate(header(PropertyNameConstants.AGGREGATOR_HEADER), new ErrorsAggregationStrategy())
                .completionPredicate(new Predicate() {
                    @Override
                    public boolean matches(Exchange exchange) {
                     ...;
                    }
                })
                .to("smtps://smtp.gmail.com?username={{remote.e-mail}}&password={{remote.password}}");

So, files with errors should be moved to directory "failed" and files without errors to directory "success". I try to generate exception after aggregating required messages (while parsing file with errors), so that to move file to directory "failed", but all files moved to directory "success", even there was an exception.

If I throw exception before aggregator, file moved to "failed" directory but last "to" (sending mail) isn't work.

도움이 되었습니까?

해결책

If you have a copy of Camel in Action, then I suggest to read chapter 8 about the aggregator EIP to understand how it works, and the fact its a stateful EIP, so there is a handoff of the Exchange, so the consumer completes. And the aggregated exchange that comes out of the aggregator is executed independently from the original consumed exchange.

Also you may want to look at the composed message processor eip, and use the spliiter only version

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top