Unable to cache SFTP connection with Spring Integr

2019-08-13 01:45发布

问题:

I need to transfer several small files via SFTP using spring integration, so I'd like to reuse a connection once established to avoid the overhead of creating a new one for every single message.

This is my current configuration:

<bean id="sftpTARGETSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
    <constructor-arg name="isSharedSession" value="true"/>
    <property name="host" value="${TARGET.push.host}"/>
    <property name="user" value="${TARGET.push.user}"/>
    <property name="privateKey" value="classpath:${TARGET.push.keyFile}"/>
    <property name="privateKeyPassphrase" value="${TARGET.push.keyFilePass}"/>
</bean>

<bean id="cachingSessionFactory"
    class="org.springframework.integration.file.remote.session.CachingSessionFactory">
    <constructor-arg ref="sftpTARGETSessionFactory"/>
    <property name="poolSize" value="2"/>
    <property name="sessionWaitTimeout" value="2000"/>
</bean>

<int-sftp:outbound-channel-adapter 
    id="sftpTARGET"
    session-factory="cachingSessionFactory"
    channel="ftpTARGET.channel"
    charset="UTF-8"
    remote-file-separator="/"
    remote-directory="${TARGET.push.path}"
    mode="REPLACE"/>

Unfortunately this doesn't work as I expected: every message opens a new ssh connection.

any hint on what's going wrong?

Using spring-integration 4.1.6 here.

thanks!