Apache 骆驼文件 zip

问题描述 投票:0回答:0

我有一个每天晚上调用的骆驼路线,通过压缩将前一天的文件从“已处理”文件夹存档到“已存档”文件夹。目前,它基于#PreviousDayFileFilter 将所有文件正确移动到“.camel”,但是当在“archived”文件夹中创建 zip 时,它只包含一个文件而不是所有文件。

注意:“processed”文件夹中的这些文件在创建时以 yyyy-MM-dd 格式作为文件名的时间戳。

例如,当调用作业并说“processed”文件夹中有前一天的 10 个文件时,.camel 文件夹中将有 9 个文件,而 archived_date 中只有第 10 个文件。邮编

这里是路由和过滤器的详细信息。有人可以指导我在这里缺少什么吗,为什么它不压缩所有文件?

骆驼路线

                from("file:C:/logs/processed?filter=#PreviousDayFileFilter" +
                        "&scheduler=spring&scheduler.cron=0+30+*+*+*+?")
                        .log(LoggingLevel.INFO, "Archival process for previous day files")
                        .aggregate(constant(true), new ZipAggregationStrategy())
                        .completionFromBatchConsumer().eagerCheckCompletion()
                        .setHeader(Exchange.FILE_NAME,
                                constant(simple("archived_${date:now-1d:yyyy-MM-dd}.zip")))
                        .to("file:/C:/logs/archived/");

PreviousDayFileFilter

    public class PreviousDayFileFilter<T> implements GenericFileFilter<T> {
        public boolean accept(GenericFile<T> file) {
            if (file.isDirectory()) {
                return true;
            }
            return file.getFileName().contains(yesterdayDate());
        }
    }

    public String yesterdayDate(){
        Instant yesterday = Instant.now().minus(1, ChronoUnit.DAYS);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
                .withZone(ZoneId.systemDefault());
        return formatter.format(instant);
    }
java apache-camel spring-camel
© www.soinside.com 2019 - 2024. All rights reserved.