2016-01-20 18 views
1

我們希望在運行時將會話工廠委派給spring sftp入站通道適配器。爲此,我們已經完成了下面的配置。如何在spring sftp入站通道適配器中配置委託會話工廠

我們已經通過了spring-sftp集成文檔,但我們不確定如何通過java設置session-factory屬性值。您能否建議我們如何使用委託會話工廠在春季sftp入站通道適配器中委託會話 - 工廠運行時間。

XML配置

<beans> 
<bean id="defaultSftpSessionFactoryOne" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory"> 
    <property name="host" value="**.***.**.***" /> 
    <property name="port" value="**" /> 
    <property name="user" value="######" /> 
    <property name="password" value="######" /> 
    <property name="allowUnknownKeys" value="true" /> 
</bean> 

<bean id="defaultSftpSessionFactoryTwo"  class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory"> 
    <property name="host" value="**.***.**.***" /> 
    <property name="port" value="**" /> 
    <property name="user" value="######" /> 
    <property name="password" value="######" /> 
    <property name="allowUnknownKeys" value="true" /> 
</bean> 

<bean id="delegatingSessionFactory"  class="org.springframework.integration.file.remote.session.DelegatingSessionFactory"> 
    <constructor-arg> 
     <bean id="factoryLocator" 
      class="org.springframework.integration.file.remote.session.DefaultSessionFactoryLocator"> 
      <constructor-arg name="factories"> 
       <map> 
        <entry key="one" value-ref="defaultSftpSessionFactoryOne"></entry> 
        <entry key="two" value-ref="defaultSftpSessionFactoryTwo"></entry> 
       </map> 
      </constructor-arg> 
     </bean> 
    </constructor-arg> 
</bean> 

<int:channel id="receiveChannel" /> 

<int-sftp:inbound-channel-adapter id="sftpInbondAdapter" auto-startup="false" 
    channel="receiveChannel" session-factory="delegatingSessionFactory" 
    local-directory="C:\\Users\\sftp" remote-directory="/tmp/archive" 
    auto-create-local-directory="true" delete-remote-files="false" 
    filename-regex=".*\.txt$"> 
    <int:poller cron="0/10 * * * * ?"> 
    </int:poller> 
</int-sftp:inbound-channel-adapter> 

Java代碼

ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml"); 
DelegatingSessionFactory<String> dsf = (DelegatingSessionFactory<String>) ac.getBean("delegatingSessionFactory"); 
SessionFactory<String> one = dsf.getFactoryLocator().getSessionFactory("one"); 
SessionFactory<String> two = dsf.getFactoryLocator().getSessionFactory("two"); 
dsf.setThreadKey("two"); 
SourcePollingChannelAdapter spca = (SourcePollingChannelAdapter) ac.getBean("sftpInbondAdapter"); 
spca.start(); 
+0

將java標籤添加到問題 – Flatlineato

回答

0

委派會議工廠真的打算出站適配器和網關。通常,入站適配器不會切換到不同的服務器。

main線程上設置線程密鑰,就像那樣什麼都不做。

您需要設置/清除調用適配器的線程上的鍵;這顯示出站適配器in the documentation

對於入站適配器,您需要在輪詢線程上執行此操作。

我不知道你會用什麼標準來選擇工廠,但你可以用smart poller來做到這一點。

+0

感謝您的信息 – ragani

相關問題