【问题标题】:Spring integration inboundChannelAdapter stops polling unexpectedlySpring 集成 inboundChannelAdapter 意外停止轮询
【发布时间】: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


【解决方案1】:

也许我的回答似乎有点太简单了,是不是因为您的 cron 表达式表明它应该将作业安排在 4 到 20 小时之间。晚上 8:00 之后,它将不再安排作业,并将在凌晨 4:00 再次开始轮询。

【讨论】:

  • 感谢 Eelco,确实我的问题还不够清楚。我们过去每分钟轮询一次,但因此节省一些资源会将轮询间隔限制为指定的间隔。但仍然是相同的行为,几个小时后轮询停止。
【解决方案2】:

事实证明,处理时间比计划的时间间隔长,因此在处理过程中已经执行了一个新任务。所以最终多个任务都试图完成同一件事。

我们通过在轮询器上使用 fixedDelay 而不是 fixedRate 解决了这个问题。 不同之处在于,如果任务完成,fixedRate 会按固定时间间隔进行调度,而 fixedDelay 会在任务完成后安排延迟。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-06
    相关资源
    最近更新 更多