跳到主要内容
版本:7.0.2

委托会话工厂

DeepSeek V3 中英对照 Delegating Session Factory

版本 4.2 引入了 DelegatingSessionFactory,它允许在运行时选择实际的会话工厂。在调用 SFTP 端点之前,你可以在工厂上调用 setThreadKey(),将某个键与当前线程关联起来。然后,该键将被用于查找要使用的实际会话工厂。使用后,你可以通过调用 clearThreadKey() 来清除该键。

我们添加了便捷方法,以便您能更轻松地在消息流中实现此操作,如下例所示:

<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)" />
important

使用会话缓存时(参见 SFTP 会话缓存),每个委托都应被缓存。不能直接缓存 DelegatingSessionFactory 本身。

从 5.0.7 版本开始,DelegatingSessionFactory 可以与 RotatingServerAdvice 结合使用,以轮询多个服务器;请参阅 入站通道适配器:轮询多个服务器和目录