委派工作階段工廠
Version 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
結合使用,以輪詢多個伺服器;請參閱 輸入通道適配器:輪詢多個伺服器和目錄。