FileReadingMessageSource.WatchServiceDirectoryScanner:关闭子目录的递归下降?

2024-01-12

版本:

Spring: 5.2.16.RELEASE
Spring Integrations: 5.3.9.RELEASE
macOS Big Sur: 11.6

我正在使用 XML 设置目录扫描器FileReadingMessageSource.WatchServiceDirectoryScanner像这样:

<int-file:inbound-channel-adapter id="channelIn" directory="${channel.dir}" auto-create-directory="false" use-watch-service="true" filter="channelFilter" watch-events="CREATE,MODIFY">
  <int-file:nio-locker ref="channelLocker"/>
  <int:poller fixed-delay="${channel.polling.delay}" max-messages-per-poll="${channel.polling.maxmsgs}"></int:poller>
</int-file:inbound-channel-adapter>

具有以下 bean 定义:

<bean id="channelLocker" class="org.springframework.integration.file.locking.NioFileLocker"/>
<bean id="channelFilter" class="org.springframework.integration.file.filters.ChainFileListFilter">
  <constructor-arg>
    <list>
      <bean class="org.springframework.integration.file.filters.SimplePatternFileListFilter">
        <constructor-arg value="SpreadSheets*.xls" />
      </bean>
      <bean id="filter" class="org.springframework.integration.file.filters.LastModifiedFileListFilter">
        <property name="age" value="${channel.filter.age}" />
      </bean>
      <ref bean="persistentFilter" />
    </list>
  </constructor-arg>
</bean>

<bean id="persistentFilter" class="org.springframework.integration.file.filters.FileSystemPersistentAcceptOnceFileListFilter">
  <constructor-arg index="0" ref="metadataStore" />
  <constructor-arg index="1" name="prefix" value="" />
  <property name="flushOnUpdate" value="false" />
</bean>

如果我查看日志org.springframework.integration.file.FileReadingMessageSource,我注意到我们注册了指定的目录(即${channel.dir}) 及其任何子目录。也就是说,我看到这样的日志:

15:44:45.706 [main] DEBUG org.springframework.integration.file.FileReadingMessageSource - registering: /Users/kc/scan.here for file events
15:44:45.711 [main] DEBUG org.springframework.integration.file.FileReadingMessageSource - registering: /Users/kc/scan.here/and.here for file events

我查看了 Spring 文档以及相关软件模块的 API 文档(例如,FileReadingMessageSource),但我没有看到任何用于关闭子目录递归下降的属性或配置选项。

这里推荐的做法是什么,仅扫描指定目录中的文件,但不进行更深层次的递归?


如果您不递归并扫描整个文件树,请不要使用该监视服务!

对于创建和修改事件,您可以配置FileSystemPersistentAcceptOnceFileListFilter它检查file.lastModified()。无论如何,我看到你这样做,因此不清楚你为什么需要手表服务?

请参阅此处讨论的一些相关内容:https://github.com/spring-projects/spring-integration/issues/3557 https://github.com/spring-projects/spring-integration/issues/3557.

如果您仍然有一些合理的理由认为仅对根目录使用监视服务,请在该问题中添加评论,我们将分别进行修改。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

FileReadingMessageSource.WatchServiceDirectoryScanner:关闭子目录的递归下降? 的相关文章

随机推荐