Spring SFTP 可变文件名-正则表达式 [英] Spring SFTP varying filename-regex
问题描述
想知道 Spring Integration SFTP 入站适配器是否支持在运行时变化的文件名正则表达式.
Wondering whether Spring Integration SFTP inbound adapter supports a filename-regex that varies at runtime.
filename-regex 看起来像 "^(foo_|bar_)" + new java.text.SimpleDateFormat("yyyyMMdd").format(new java.util.Date()) +".txt$"
filename-regex will look like "^(foo_|bar_)" + new java.text.SimpleDateFormat("yyyyMMdd").
format(new java.util.Date()) +".txt$"
我在入站适配器设置中设置了 auto-startup="true".
I have auto-startup="true" set in the inbound adapter settings.
在我的测试案例中,轮询器的固定速率="1000" time-unit="MILLISECONDS",它将当天的正确文件复制到本地目录.但是,如果我在轮询期间更改系统日期,则它不会获取新日期的文件.如果我重新运行测试,它会起作用.
In my test case, with a poller at fixed-rate="1000" time-unit="MILLISECONDS", it copies the right file for that day to the local directory. However, if I change the system date while it is still polling, it's not picking up the new date's file. If I rerun the test, it works.
我的理解是它应该可以工作.不是因为它是从 JUnit 运行的吗?
My understanding is it should work. Is it not because it's running from JUnit?
推荐答案
您可以子类化 SftpRegexPatternFileListFilter
并在每次调用 accept
- setPattern 时更新模式
和 返回 super.accept(file)
.
You could subclass the SftpRegexPatternFileListFilter
and update the pattern on each call to accept
- setPattern
and return super.accept(file)
.
您可以将其优化为仅在检测到日期更改时编译新模式.
You could optimize it to only compile a new pattern when you detect a date change.
这篇关于Spring SFTP 可变文件名-正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!