委託會話工廠
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 結合使用來輪詢多個伺服器;參見入站通道介面卡:輪詢多個伺服器和目錄。