【发布时间】:2020-04-06 09:04:55
【问题描述】:
在我们的项目中,我们需要从远程 ftp 服务器检索价格。在办公时间内,这工作正常,价格被检索并成功处理。办公时间之后,ftp 服务器上没有发布新价格,所以正如预期的那样,我们没有发现任何新价格。
我们的问题是,在几个小时没有找到新价格之后,轮询器就停止了轮询。日志文件中没有错误(即使在调试级别上运行 org.springframework.integration)也没有异常。我们现在使用单独的TaskExecutor 来隔离问题,但轮询器仍然停止。与此同时,我们调整了 cron 表达式以匹配这些时间,以限制资源使用,但轮询器仍然在应该运行时停止。
非常感谢任何解决此问题的帮助!
我们在FtpStreamingMessageSource 上使用@InboudChannelAdapter,其配置如下:
@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)
【问题讨论】:
-
是轮询器刚刚停止,还是线程处于阻塞状态?您可能想尝试使用 TRACE 级别而不是 DEBUG 并添加
org.apache.commons.net.ftp(因为这是正在使用的底层 FTP 客户端)。 -
谢谢,我们看看会记录什么
-
您可能要检查的另一个组是
org.springframework.scheduler(至少在 INFO 级别)。另一个有趣的事情是查看TaskExecutor的配置。
标签: ftp integration poller