gpt4 book ai didi

java - 带有监视服务和 LastModifiedFileListFilter 的 Spring Integration 文件轮询器

转载 作者:行者123 更新时间:2023-11-30 10:25:04 24 4
gpt4 key购买 nike

我想知道是否有人知道我是否可以在 FileInboundChannelAdapter 中使用监视服务以及 LastModifiedFileListFilter?

下面的示例代码给出了相当不一致的结果。有时,文件只是位于文件夹中并且未被处理。

我怀疑监视服务可能与 LastModifiedFileListFilter 不兼容。例如

  • 如果 LastModifiedFileList 过滤器设置为查找至少 5 个文件秒,轮询器设置为每 10 秒轮询一次。
  • 在第 9 秒,可以在监视文件夹中创建一个文件。
  • 在 10 秒时,轮询器查询 watch 服务以找出什么在过去 10 秒内更改。
  • 它找到新创建的文件。

  • 新创建的最后修改时间为-1秒,所以它不处理它。

  • 在 20 秒时,轮询器查询 watch 第二次服务,这次没有看到未处理的10 多秒前创建的文件。

有没有人有这方面的经验?是否有推荐的方法来解决此问题并允许我在继续之前验证文件是否已完全写入?

@Bean
public IntegrationFlow ftpInputFileWatcher()
{
return IntegrationFlows.from(ftpInboundFolder(), filePoller())
.handle()
/*abbreviated*/
.get();
}

private FileInboundChannelAdapterSpec ftpInboundFolder() {
LastModifiedFileListFilter lastModifiedFileListFilter = new LastModifiedFileListFilter();
lastModifiedFileListFilter.setAge(5);

return Files.inboundAdapter(inboundFolder)
.preventDuplicates(false)
.useWatchService(true)
.filter(fileAgeFilterToPreventPrematurePickup());
}

protected Consumer<SourcePollingChannelAdapterSpec> filePoller(){
return poller -> poller.poller((Function<PollerFactory, PollerSpec>) p -> p.fixedRate(2000));
}

谢谢!

最佳答案

是的,这很好!

对,他们不兼容。 WatchService 是基于事件的,并将来自事件的文件存储到内部队列中。当轮询器触发其操作时,它会从该队列中轮询文件并应用其过滤器。由于 LastModifiedFileListFilter 丢弃该文件并且不再有任何事件,我们将不会再看到该文件。

请就此事提出一个 JIRA,我们会考虑如何成为。

同时,作为变通方法,不要将 WatchService 用于此类逻辑。

关于java - 带有监视服务和 LastModifiedFileListFilter 的 Spring Integration 文件轮询器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46417689/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com