委託會話工廠
版本 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)" />
使用會話快取時(參見 SFTP 會話快取),應快取每個委託。不能快取 DelegatingSessionFactory 本身。 |
從版本 5.0.7 開始,DelegatingSessionFactory
可以與 RotatingServerAdvice
結合使用來輪詢多個伺服器;參見 入站通道介面卡:輪詢多個伺服器和目錄。