【问题标题】:How to configure Delegating Session Factory in spring sftp inbound channel adaptor如何在spring sftp入站通道适配器中配置委托会话工厂
【发布时间】:2016-01-20 14:19:52
【问题描述】:

我们希望在运行时将会话工厂委托给 spring sftp 入站通道适配器。为此,我们完成了以下配置。

我们已经阅读了 spring-sftp 集成文档,但我们不确定如何通过 java 设置 session-factory 属性值。您能否建议我们如何使用委托会话工厂在 spring 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();

【问题讨论】:

  • 给问题添加java标签

标签: spring spring-integration


【解决方案1】:

委派会话工厂实际上是为出站适配器和网关设计的。通常,入站适配器不会切换到不同的服务器。

像这样在main 线程上设置线程键没有任何作用。

您需要在调用适配器的线程上设置/清除密钥;这是针对出站适配器 in the documentation 显示的。

对于入站适配器,您需要在轮询线程上进行。

我不知道你会用什么标准来选择工厂,但你可以使用smart poller来做。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-17
    • 1970-01-01
    • 1970-01-01
    • 2014-06-29
    相关资源
    最近更新 更多