使用 ftp 适配器时的最大同时连接数

Maximum simultaneous connection when using ftp adapter

我可以调整什么来解决这个最大连接数问题?有什么方法可以指定限制? 这来自 Spring 集成应用程序。

 <int-ftp:outbound-channel-adapter id="matasLiveProdSdkOutbound"
                                      channel="ftpOutboundChannel"
                                      session-factory="ftpsSessionFactory"
                                      charset="UTF-8"
                                      auto-create-directory="true"
                                      use-temporary-file-name="false"
                                      remote-file-separator="/"
                                      remote-directory-expression="${egnyte.remote.dir}"
                                      mode="IGNORE">
</int-ftp:outbound-channel-adapter>

这是我得到的错误:

Caused by: org.springframework.messaging.MessagingException: Failed to execute on session; nested exception is java.lang.IllegalStateException: failed to create FTPClient
    at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:343)
    at org.springframework.integration.ftp.session.FtpRemoteFileTemplate.doExecuteWithClient(FtpRemoteFileTemplate.java:51)
    at org.springframework.integration.ftp.session.FtpRemoteFileTemplate.executeWithClient(FtpRemoteFileTemplate.java:47)
    at org.springframework.integration.ftp.session.FtpRemoteFileTemplate.exists(FtpRemoteFileTemplate.java:62)
    at org.springframework.integration.file.remote.RemoteFileTemplate.sendFileToRemoteDirectory(RemoteFileTemplate.java:435)
    ... 70 more
Caused by: java.lang.IllegalStateException: failed to create FTPClient
    at org.springframework.integration.ftp.session.AbstractFtpSessionFactory.getSession(AbstractFtpSessionFactory.java:171)
    at org.springframework.integration.ftp.session.AbstractFtpSessionFactory.getSession(AbstractFtpSessionFactory.java:41)
    at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:332)
    ... 74 more
Caused by: javax.net.ssl.SSLException: 550 Cannot connect. You have reached maximum allowed simultaneous connections 7 per user.

编辑: 添加一个 CachingSessionFactory,就像 Gary 建议的那样...

@Bean
    public CachingSessionFactory ftpsCachingSessionFactory(DefaultFtpsSessionFactory ftpsSessionFactory) {
        CachingSessionFactory cachingSessionFactory = new CachingSessionFactory(ftpsSessionFactory, 5);
        cachingSessionFactory.setSessionWaitTimeout(1000);
        return cachingSessionFactory;
    }

我已将 ftps 会话工厂包装在 cachingSessionFactoy 中。现在,当我从上面的 ftp 出站适配器引用这个 bean 时,我得到一个错误,告诉我这个 bean 必须是 AbstractFtpSessionFactory 类型。在 FTP 出站适配器中使用 FTPS 缓存会话工厂是不可能的 - 就像上面的那样?我找不到任何 int-ftps 名称空间来切换适配器。 spring-integration-ftp-4.1xsd 预计只接受 org.springframework.integration.ftp.session.DefaultFtpSessionFactory

将会话工厂包装在 CachingSessionFactory 中。使用 this constructor 可以限制会话数。

另见 setSessionWaitTimeout