此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Integration 6.5.1spring-doc.cadn.net.cn

委托会话工厂

4.2 版引入了DelegatingSessionFactory,这允许在运行时选择实际的会话工厂。 在调用 SFTP 端点之前,您可以调用setThreadKey()在工厂上将键与当前线程相关联。 然后,该密钥用于查找要使用的实际会话工厂。 您可以通过调用clearThreadKey()使用后。spring-doc.cadn.net.cn

我们添加了便利方法,以便您可以更轻松地从消息流中执行此作,如以下示例所示:spring-doc.cadn.net.cn

<bean id="dsf" class="org.springframework.integration.file.remote.session.DelegatingSessionFactory">
    <constructor-arg>
        <bean class="o.s.i.file.remote.session.DefaultSessionFactoryLocator">
            <!-- delegate factories here -->
        </bean>
    </constructor-arg>
</bean>

<int:service-activator input-channel="in" output-channel="c1"
        expression="@dsf.setThreadKey(#root, headers['factoryToUse'])" />

<int-sftp:outbound-gateway request-channel="c1" reply-channel="c2" ... />

<int:service-activator input-channel="c2" output-channel="out"
        expression="@dsf.clearThreadKey(#root)" />
使用会话缓存时(请参阅 SFTP 会话缓存),应缓存每个委托。 您无法缓存DelegatingSessionFactory本身。

从 5.0.7 版本开始,DelegatingSessionFactory可以与RotatingServerAdvice轮询多个服务器;请参阅入站通道适配器:轮询多个服务器和目录spring-doc.cadn.net.cn