本文介绍了Apache Camel pollEnrich不会复制所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一条骆驼路线,如下图所示

I've a camel route which looks like below

from("activemq:queue:upload" )
    .pollEnrich().simple("file:basePath/${header.ID}?noop=true&recursive=true")
    .aggregationStrategy(new ExampleAggregationStrategy())
    .timeout(2000)
 .toD("ftp:${header.destinationURI}")

在我的文件系统中,file:basePath/${header.ID}包含多个文件夹.当执行上述路由时,仅将第一个文件夹中的第一个文件复制到ftp服务器.剩余的文件夹(带有子文件夹)不会被复制到ftp服务器!

In my file system file:basePath/${header.ID} contains multiple folders. When above route is executed, only 1st file from the 1st folder will be copied to ftp server. Remaining folders(with subfolders) aren't getting copied to ftp server!

ExampleAggregationStrategy()类的aggregate()方法如下所示

@Override
        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
            String destinationURI = "populatedURI";

        oldExchange.setOut(newExchange.getIn());
        oldExchange.getOut().setHeader("ID",  oldExchange.getIn().getHeader("ID"));
        oldExchange.getOut().setHeader("destinationURI", destinationURI);
        oldExchange.setFromEndpoint(newExchange.getFromEndpoint());
        oldExchange.setFromRouteId(newExchange.getFromRouteId());

            return oldExchange;
        }

我也尝试设置properties and onCompletions.还是没有运气!我在aggregationStrategy中缺少任何内容吗?
如何使用pollEnrich成功复制所有文件和文件夹?

I've tried setting properties and onCompletions as well. Still no luck !Am I missing anything in aggregationStrategy ?
How to copy all the files and folders successfully using pollEnrich?

推荐答案

我知道这是一个老问题,但是我有类似的问题,可以使用loopDoWhile()解决.这是我的路线:

I know it's an old question but I had similar problem and I solve it using loopDoWhile(). Here's my route:

from("direct:start")
    .setProperty("StartDate", simple("${date:now:yyyy-MM-dd'T'HH-mm-ss}"))
    .to("direct:download");

from("direct:download")
    .loopDoWhile(body().isNotNull())
        .pollEnrich()
        .simple("sftp://{{remote.user}}@{{remote.url}}/{{remote.directory}}?password={{remote.password}}"
                + "&move=.done/${property.StartDate}"
                + "&localWorkDirectory=work/tmp"
                + "&autoCreate=false"
                + "&consumer.bridgeErrorHandler=true"
                + "&throwExceptionOnConnectFailed=true"
                + "&recursive=true"
        )
        .timeout(0)
        .choice()
            .when(body().isNotNull())
                .to("file:work/inbox/?fileName=${file:name}")
            .otherwise()
                .end()
    .end();

我希望这会对某人有所帮助.

I hope it will be helpful for someone.

这篇关于Apache Camel pollEnrich不会复制所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:45