Apache Camel FTP 删除小于指定数量的文件时进入无限循环

Apache Camel FTP goes into endless loop when deleting files which are less than the specified amount

我按照 Apache Camel Route 进行设置,它从 FTP 服务器读取 XML 文件,将内容转换为 Java 对象,聚合创建的 Java 对象一个 List,然后将 List 转储到一个 Direct 对象中,以供 ConsumerTemplate 读取。待处理文件数量为10.

这是我的路线:

JAXBContext jaxbContext = JAXBContext.newInstance(new Class[]{Dokumente.class});
JaxbDataFormat jaxbDataFormat = new JaxbDataFormat();
jaxbDataFormat.setContext(jaxbContext);

from("ftp://tstusr@localhost/uploads/Replies?delete=true&password=ftpServPW&passiveMode=true&binary=true&disconnect=true")
        .unmarshal(jaxbDataFormat)
        .aggregate(AggregationStrategies.flexible(Dokumente.class).accumulateInCollection(LinkedList.class))
        .constant(true)
        .completionSize(10)
        .to("direct:files");

除了“delete=true”部分外,路线正在做它应该做的事情。当我的目录中的文件少于 10 个时,程序会进入无限循环。在我的 FTP (FileZilla Server) 的本地测试服务器中,我可以看到它登录、更改目录、执行 LIST 命令然后退出。它在无限循环中重复执行此操作。

如何修复路由以阻止它这样做?我不知道目录中有多少文件。这意味着总是可以小于批量大小。我正在使用 Apache Camel 3.11.4 版。

问题是如果可用文件少于指定的文件数量,路由会一直等待丢失的文件出现。

所以如果它被告知要下载 10 个文件,但只有 2 个存在,它将等待 8 个丢失的文件。

我不得不先给它一个 ID 来手动终止路线。然后我必须设置路由选项 sendEmptyMessageWhenIdle=true 并附加一个处理器,该处理器在收到空消息时停止路由。由于空消息不执行任何操作,我随后将其过滤掉,然后强制 com 调整后的路由如下所示

        from("ftp://dm@localhost/uploads/Replies?delete=true&password=ftpPass&passiveMode=true&binary=true&disconnect=true&sendEmptyMessageWhenIdle=true") 
            .routeId("ftpRoute")
            .process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    if (exchange.getMessage().getBody() == null) {
                        exchange.getContext().getRouteController().stopRoute("ftpRoute");
                    }
                }
            })
            .filter(simple("${body} != null"))
            .unmarshal(jaxbDataFormat)
            .aggregate(AggregationStrategies.flexible(Dokumente.class).accumulateInCollection(LinkedList.class)) 
            .constant(true) 
            .completionSize(10) 
            .forceCompletionOnStop()
            .to("direct:files");