首页 > 解决方案 > 如何在 Apache Camel 路由中再次读取跳过的文件?

问题描述

我正在使用 apache camelfile组件从目录中读取所有文件。根据文件大小(如果列表中的文件大小与我当前正在阅读的文件大小不同),我想跳过该文件并在下一次迭代中再次选择它。那可能吗?我的代码剪断如下:

from("file://my/directroy/path/?recursive=true&noop=true&idempotent=false")
.aggregate(constant(true), new AggregationStrategy())
.completionSize(100).completionTimeout(100)
.split(body()).process(new Processor() {
  public void process(Exchange exchange){
     //Move this file only if the size is == new File("thisPath").length();
    // othersize skip this for now and pick it up in next iteration
  }
});

标签: javafileapache-camel

解决方案


https://camel.apache.org/components/3.4.x/file-component.html

根据文档,您可以使用:

filterFile (filter)
    

Filters the file based on Simple language. For example to filter on file size, you can use \${file:size} 5000

它看起来像:

    from(file:{{replayDir}}/?filterFile=${file:size} 5000

有关简单语言支持,请参阅https://cwiki.apache.org/confluence/display/CAMEL/Simple

在此处输入图像描述


推荐阅读