防止apache camel将非限定文件移动到.camel

防止apache camel将非限定文件移动到.camel,apache,apache-camel,Apache,Apache Camel,我正在创建一个简单的文件传输实用程序,根据用户输入搜索文件夹中的文件,并将匹配的文件传输到目标。问题 is camel正在移动所有不匹配的文件。camel文件夹我不希望发生这种情况。下面是我的代码片段 from("file:C:\\input?noop=true;"). filter(header(Exchange.FILE_NAME) .contains("xyz")).split(body().tokenize("\n")). s

我正在创建一个简单的文件传输实用程序,根据用户输入搜索文件夹中的文件,并将匹配的文件传输到目标。问题 is 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");

提前谢谢

在noop=true之后删除分号,属性将开始禁止将处理过的文件移动到.camel


已处理的文件是所有已处理的文件,因此即使是匹配的文件也将保留在C:\input目录中。使用noop=true时,默认的幂等存储库位于内存中。因此,重新启动应用程序后,已处理的文件将再次处理。因此,您需要创建自己的非内存幂等重映射。

请查看文件组件使用者选项:。您应该能够在from uri中使用“filter”或“filterFile”选项。正如克劳斯上面提到的,这些将在端点过滤。如果您能够使用简单的语言,则filterFile将更加简洁:

from("file:C:\\input?filterFile=...
否则,您可以创建一个过滤器bean来处理过滤,并使用过滤器选项来引用该bean。请注意,不再需要筛选器().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
    }
}
from(“文件:C:\\input?过滤器=#someFileFilter”)
.split(body().tokenize(“\n”))
.streaming()
.bean(LineParser.class,“进程”)
.to(“文件:“+Constants.getMapping().get(argumentName)+”?fileExist=Append”);
公共类SomeFileFilter实现GenericFileFilter{
@凌驾
公共布尔接受(GenericFile){
//如果应该包括文件,则返回true;如果排除文件,则返回false
}
}

您需要直接在from端点中过滤文件名,请参阅文件文档中的include/exclude选项。谢谢Ryan,因为过滤逻辑有点复杂,所以选择了通用过滤器。