首页 > 解决方案 > 防止 apache camel 将不合格的文件移动到 .camel

问题描述

我正在创建一个简单的文件传输实用程序,根据用户输入搜索文件夹中的文件并将匹配的文件传输到目的地。问题是骆驼正在移动所有与 .camel 文件夹不匹配的文件,我不希望这种情况发生在下面是我的片段。

        from("file:C:\\input?noop=true;").
        filter(header(Exchange.FILE_NAME)
       .contains("xyz")).split(body().tokenize("\n")).
        streaming().bean(LineParser.class, "process").
        to("file:"+ Constants.getMapping().get(argumentName)+"? 
         fileExist=Append");

提前致谢 !!

标签: apacheapache-camel

解决方案


查看文件组件使用者选项:http ://camel.apache.org/file2.html 。您应该能够在 from uri 中使用“filter”或“filterFile”选项。正如克劳斯上面提到的,这些将在端点过滤。如果您能够使用 Simple 语言,则 filterFile 会更简洁:

from("file:C:\\input?filterFile=...

否则,您可以创建一个过滤器 bean 来处理过滤并使用过滤器选项来引用该 bean。请注意,不再需要 filter().contains() :

from("file:C:\\input?filter=#someFileFilter")
    .split(body().tokenize("\n"))
    .streaming()
    .bean(LineParser.class, "process")
    .to("file:"+ Constants.getMapping().get(argumentName)+"?fileExist=Append");

public class SomeFileFilter<T> implements GenericFileFilter<T> {
    @Override
    public boolean accept(GenericFile<T> file) {
        // return true if file should be included, false if excluded
    }
}

推荐阅读