Camel文件组件 - 跳过文件

时间:2016-06-17 07:58:19

标签: apache-camel

我正在使用camel文件组件来轮询目录中的文件。 在我处理文件之前,必须满足一些条件, 如果不是驼峰应该跳过该文件而不删除/移动它 去下一个。

要做到这一点,我用这个:

public InputStream myMethod(@Body InputStream is, @Headers .....) {

if( !checkPrerequisites )
    throw new MyRuntimeException("conditions not satisfied yet");

所以我想知道是否有其他方法来存档所需的行为。

1 个答案:

答案 0 :(得分:4)

您可以实施GenericFileFilter。创建过滤器,如下所示:

public class AnotherFileExistsFilter<T> implements GenericFileFilter<T> {

    @Override
    public boolean accept(GenericFile<T> firstFile) {
        return Files.exists(Paths.get("/some/other/folder/" + firstFile.getFileName()));
    }
}

使用filter=#anotherFileExistsBeanName将其添加到您的终端。

如果要继续检查文件,请设置idempotent=false,我建议设置延迟(delay=xxx毫秒),以便不连续轮询文件夹。

更多详情请见Apache Camel File2 page

相关问题