【问题标题】:Spring integration FTP InboundChannelAdapter dies after network reset网络重置后 Spring 集成 FTP InboundChannelAdapter 死机
【发布时间】:2016-05-25 13:52:10
【问题描述】:

我们有一个从 FTP 到 download 文件的用例,并且有一个奇怪的行为,即 ftp 入站适配器在网络重置后停止工作,这里是重现问题的步骤:

  1. 启动应用程序
  2. 应用程序开始将文件从 ftp 服务器下载到本地
  3. 定义的本地目录中出现了filename.writing文件
  4. 拔出网线(模拟网络重置情况)
  5. 应用程序停止下载文件(显然没有网络连接)
  6. 插入网线。
  7. 下载未重新启动或重置,应用程序保持静止..
  8. 根本没有LOG 来识别这个问题。

提前致谢!

更新

这个问题应该通过添加超时defSession.setConnectTimeout(Integer.valueOf(env.getProperty("ftp.timeout.connect")));来解决

AND下面的代码是FTP读取客户端的工作示例

这里是sn-p的代码:

    @Bean
    public DefaultFtpSessionFactory ftpSessionFactory() {
        DefaultFtpSessionFactory defSession = new DefaultFtpSessionFactory();
        defSession.setUsername(env.getProperty("ftp.username"));
        defSession.setPassword(env.getProperty("ftp.password"));
        defSession.setPort(21);
        defSession.setHost(env.getProperty("ftp.host"));

        defSession.setClientMode(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE);
        defSession.setControlEncoding("UTF-8");

        return defSession;
    }

    @Bean
    PollableChannel ftpChannel() {
        return new QueueChannel(Integer.valueOf(env.getProperty("ftp.channel.size")));
    }

    @Bean
    public FtpInboundFileSynchronizer ftpInboundFileSynchronizer() {
        FtpInboundFileSynchronizer ftpInboundFileSynchronizer = new FtpInboundFileSynchronizer(ftpSessionFactory());
        ftpInboundFileSynchronizer.setDeleteRemoteFiles(Boolean.valueOf(env.getProperty("ftp.directory.delete")));

        FtpRegexPatternFileListFilter ftpRegexPatternFileListFilter = new FtpRegexPatternFileListFilter(pattern);
        ftpInboundFileSynchronizer.setFilter(ftpRegexPatternFileListFilter);
        ftpInboundFileSynchronizer.setRemoteDirectory(env.getProperty("ftp.directory.remote"));

        return ftpInboundFileSynchronizer;
    }

    @Bean
    @InboundChannelAdapter(value = "ftpChannel")
    public FtpInboundFileSynchronizingMessageSource ftpInboundFileSynchronizingMessageSource() {
        FtpInboundFileSynchronizingMessageSource ftpInboundFileSynchronizingMessageSource = new FtpInboundFileSynchronizingMessageSource(ftpInboundFileSynchronizer());
        ftpInboundFileSynchronizingMessageSource.setLoggingEnabled(true);
        ftpInboundFileSynchronizingMessageSource.setCountsEnabled(true);
        ftpInboundFileSynchronizingMessageSource.setAutoCreateLocalDirectory(true);
        ftpInboundFileSynchronizingMessageSource.setLocalDirectory(new File(env.getProperty("ftp.directory.local")));

        return ftpInboundFileSynchronizingMessageSource;
    }

    @Bean(name = PollerMetadata.DEFAULT_POLLER)
    public PollerMetadata defaultPoller() {
        PollerMetadata pollerMetadata = new PollerMetadata();
        pollerMetadata.setErrorHandler(t -> log.error("Failed to retrieve data from FTP: {}", t.getMessage(), t));
        pollerMetadata.setTrigger(new PeriodicTrigger(60, TimeUnit.SECONDS));
        return pollerMetadata;
    }

【问题讨论】:

    标签: spring ftp spring-integration spring-integration-sftp


    【解决方案1】:

    很可能线程仍然挂在读取上 - 如果您从计算机上的实际适配器中拔出电缆,网络堆栈应通知 java 进程套接字已消失,但如果您从下游拔出电缆路由器,可能没有信号。 jstack 将显示线程正在做什么。

    您需要在会话工厂上设置超时 - 请参阅 the documentation 和 FtpClient javadocs - dataTimeout 用于读取。

    【讨论】:

    • 谢谢!在我们的情况下,电缆已从下游拉出,我会尝试一下,让您知道是否是这个原因,另一个问题是,为什么spring-integration-ftp模块的登录很少,我们如何改进它?跨度>
    • 我不确定您所说的“很少”是什么意思 - 如果线程在读取时“卡住”,则无法记录任何内容。当它正常运行时,您可以使用 DEBUG 日志记录来获取更多日志。
    • 我们设置了logging.level.org.springframework.integration: TRACE,我得到的唯一日志是2016-05-25 16:32:11.677 DEBUG 24075 --- [ask-scheduler-5] o.s.i.f.s.DefaultFtpSessionFactory : Connected to server [ip]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    • 2016-07-27
    • 2013-02-04
    • 1970-01-01
    相关资源
    最近更新 更多