如果上次修改日期超过特定时间,我如何告诉 Camel 仅复制文件? [英] How can I tell Camel to only copy a file if the Last Modified date is past a certain time?

查看:27
本文介绍了如果上次修改日期超过特定时间,我如何告诉 Camel 仅复制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这是否可以通过 Apache Camel 实现.我想做的是让 Camel 查看文件目录,并且只复制上次修改"日期比某个日期更近的文件.例如,只复制 2014 年 2 月 7 日之后修改的文件.基本上我想在每次 Camel 运行时更新上次运行日期"的变量,然后检查文件是否在上次运行后被修改.

I'm wondering if this is possible to achieve with Apache Camel. What I would like to do, is have Camel look at a directory of files, and only copy the ones whose "Last Modified" date is more recent than a certain date. For example, only copy files that were modified AFTER February 7, 2014. Basically I want to update a variable for the "Last Run Date" every time Camel runs, and then check if the files were modified after the Last Run.

我想使用文件上的实际时间戳,而不是 Camel 提供的任何内容...据我所知,Camel 中有一种已弃用的方法,用于在 Camel 查看文件时标记文件,然后让您知道它们是否已被处理.但此功能已弃用,因此我需要一个替代方案.

I would like to use the actual timestamp on the file, not anything provided by Camel... it is my understanding that there is a deprecated method in Camel that used to stamp files when Camel looked at them, and then that would let you know whether they have been processed already or not. But this functionality is deprecated so I need an alternative.

Apache 建议在处理后移动或删除文件以了解它是否已被处理,但这对我来说不是一个选项.有任何想法吗?提前致谢.

Apache recommends moving or deleting the file after processing to know whether it has been processed, but this is not an option for me. Any ideas? Thanks in advance.

已解决 (2014-02-10):

SOLVED (2014-02-10):

import java.util.Date;

import org.apache.camel.builder.RouteBuilder;

public class TestRoute extends RouteBuilder {

    static final long A_DAY = 86400000;

    @Override
    public void configure() throws Exception {

        Date yesterday = new Date(System.currentTimeMillis() - A_DAY);

        from("file://C:\\TestOutputFolder?noop=true").
            filter(header("CamelFileLastModified").isGreaterThan(yesterday)).
            to("file://C:\\TestInputFolder");

    }

}

无需 XML 配置.感谢下面的回答.

No XML configuration required. Thanks for the answers below.

推荐答案

是的,您可以实现过滤器,然后返回 true|false 如果您想包含或不包含文件.在该逻辑中,您可以检查文件修改并查看文件是否超过 X 天等.

Yes you can implement a filter and then return true|false if you want to include the file or not. In that logic you can check the file modification and see if the file is more than X days old etc.

请参阅位于

并寻找过滤器选项,例如您在何处实现 org.apache.camel.component.file.GenericFileFilter 接口.

And look for the filter option, eg where you implement org.apache.camel.component.file.GenericFileFilter interface.

这篇关于如果上次修改日期超过特定时间,我如何告诉 Camel 仅复制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆