【发布时间】:2021-12-20 15:35:18
【问题描述】:
我已经设置了 Apache Camel Route,它从 FTP 服务器读取 XML 文件,将内容转换为 Java 对象,将创建的 Java 对象聚合到列表中,然后将列表转储到直接对象以供 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");
Route 正在做它应该做的事情,除了“delete=true”部分。当我的目录中的文件少于 10 个时,程序进入无限循环。在我的本地 FTP 测试服务器(FileZilla 服务器)中,我可以看到它登录、更改目录、执行 LIST 命令然后退出。它在无限循环中重复执行此操作。
如何修复 Route 以阻止它这样做?我不知道目录中有多少文件。这意味着总有可能小于批量大小。我使用的是 3.11.4 版的 Apache Camel。
【问题讨论】:
-
你确定那个无限循环吗? FTP 是一个轮询消费者,因此默认情况下它每隔500ms 左右检查一次新文件。
标签: java ftp apache-camel filezilla