FileReadingMessageSource.WatchServiceDirectoryScanner:是否关闭到子目录的递归下降? [英] FileReadingMessageSource.WatchServiceDirectoryScanner: turn off recursive descent into sub-directories?
本文介绍了FileReadingMessageSource.WatchServiceDirectoryScanner:是否关闭到子目录的递归下降?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
版本:
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
),但是我没有看到任何属性或配置选项来关闭递归下降到子目录。
对于仅扫描指定目录内的文件,而不递归更深层次的文件,这里的建议做法是什么?
推荐答案
如果不进行递归并扫描整个文件树,请不要使用监视服务!
对于创建和修改事件,您可以配置检查file.lastModified()
的FileSystemPersistentAcceptOnceFileListFilter
。我看你还是这么做的,所以不清楚你为什么需要手表服务?
请参阅此处讨论的一些相关内容:https://github.com/spring-projects/spring-integration/issues/3557。
如果您仍有合理理由仅对根目录使用监视服务,请在该问题中添加注释,我们将分别对其进行修改。
这篇关于FileReadingMessageSource.WatchServiceDirectoryScanner:是否关闭到子目录的递归下降?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文