在我们的项目中,我们需要从远程ftp服务器检索价格。在办公时间内,此工作正常,可以检索价格并成功处理。在办公时间之后,ftp服务器上没有发布新价格,因此,正如我们所料,我们没有发现任何新价格。
我们的问题是,经过几个小时找不到新价格后,轮询器才停止轮询。日志文件中没有错误(即使在调试级别在org.springframework.integration
上运行时),也没有异常。现在,我们使用单独的TaskExecutor
来隔离问题,但轮询器仍然停止。同时,我们调整了cron表达式以匹配这些时间,以限制资源使用,但是轮询器仍然在应该运行时停止。
非常感谢您解决此问题的任何帮助!
我们在配置如下的@InboudChannelAdapter
上使用FtpStreamingMessageSource
:
@Bean
@InboundChannelAdapter(
value = FTP_PRICES_INBOUND,
poller = [Poller(
maxMessagesPerPoll = "\${ftp.fetch.size}",
cron = "\${ftp.poll.cron}",
taskExecutor = "ftpTaskExecutor"
)],
autoStartup = "\${ftp.fetch.enabled:false}"
)
fun ftpInboundFlow(
@Value("\${ftp.remote.prices.dir}") pricesDir: String,
@Value("\${ftp.remote.prices.file.pattern}") remoteFilePattern: String,
@Value("\${ftp.fetch.size}") fetchSize: Int,
@Value("\${ftp.fetch.enabled:false}") fetchEnabled: Boolean,
clock: Clock,
remoteFileTemplate: RemoteFileTemplate<FTPFile>,
priceParseService: PriceParseService,
ftpFilterOnlyFilesFromMaxDurationAgo: FtpFilterOnlyFilesFromMaxDurationAgo
): FtpStreamingMessageSource {
val messageSource = FtpStreamingMessageSource(remoteFileTemplate, null)
messageSource.setRemoteDirectory(pricesDir)
messageSource.maxFetchSize = fetchSize
messageSource.setFilter(
inboundFilters(
remoteFilePattern,
ftpFilterOnlyFilesFromMaxDurationAgo
)
)
return messageSource;
}
属性值为:
poll.cron: "*/30 * 4-20 * * MON-FRI"
fetch.size: 10
fetch.enabled: true
我们限制了每分钟使用检索的poll.cron。
在相关的DefaultFtpSessionFactory
中,超时设置为60秒以覆盖默认值-1(这意味着完全没有超时:]
sessionFactory.setDataTimeout(timeOut)
sessionFactory.setConnectTimeout(timeOut)
sessionFactory.setDefaultTimeout(timeOut)
也许我的回答似乎有点太简单了,是因为您的cron表达式指出应将作业安排在4到20小时之间。 8:00 PM之后,它将不再计划作业,它将在4:00 AM重新开始轮询。