如需使用最新稳定版本,请使用 Spring Integration 7.0.4spring-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