使用Spring Integration在不同服务器(sftp)上传输文件

时间:2016-04-28 20:35:39

标签: spring spring-integration sftp

我需要在SI中构建一个应用程序,它读取一个输入目录,该目录可能包含1000个文件,并将它们复制到远程服务器,比如10个服务器,处理器实例会将它们接收进行处理。文件的移动应该是采用循环方式,以便在处理任何服务器时不会有额外的负担。详细说明一下 - 假设我们在输入目录中有10个文件,那么应用程序应该复制 server1上的文件1, server2上的file2 。 。 。 .... 服务器10上的文件10.

顺序并不重要,每个服务器都应该有相同的负载。我对Spring Integration相当新,但是我发现了一个使用SI做文件sftp的示例

https://github.com/spring-projects/spring-integration-samples/tree/master/basic/sftp

但我不知道如何为多台服务器配置它并且有一个算法以循环方式移动文件。

我将不胜感激任何提示或建议。

我可以使用下面的配置来执行sftp。

<context:property-placeholder location="classpath:app.properties" />

<int-file:inbound-channel-adapter id="ReaderChannel"
    directory="file:${input.file.dir}" filename-pattern="*.*"
    prevent-duplicates="true" ignore-hidden="true" auto-startup="true">
    <int:poller id="poller" fixed-rate="1" task-executor="myTaskExecutor" />
</int-file:inbound-channel-adapter>

<int-task:executor id="myTaskExecutor"  pool-size="${file.concurrentFilesNum}" queue-capacity="0"   rejection-policy="CALLER_RUNS" />

<int-sftp:outbound-channel-adapter  id="sftpOutboundAdapter" session-factory="sftpSessionFactory" channel="ReaderChannel"
    charset="UTF-8" remote-directory="${output.file.dir}" auto-startup="true">
    <int-sftp:request-handler-advice-chain>
        <int:retry-advice />
    </int-sftp:request-handler-advice-chain>
</int-sftp:outbound-channel-adapter>

<beans:bean id="sftpSessionFactory"     class="org.springframework.integration.file.remote.session.CachingSessionFactory">
    <beans:constructor-arg ref="defaultSftpSessionFactory" />
</beans:bean>

<beans:bean id="defaultSftpSessionFactory"
    class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
    <beans:property name="host" value="${sftp.host}" />
    <beans:property name="privateKey" value="${sftp.private.keyfile}" />
    <beans:property name="privateKeyPassphrase" value="${sftp.private.passphrase}" />
    <beans:property name="port" value="${sftp.serverPort}" />
    <beans:property name="user" value="${sftp.username}" />
    <beans:property name="allowUnknownKeys" value="true" />
</beans:bean>

1 个答案:

答案 0 :(得分:1)

round-robin隐藏在DirectChannel UnicastingDispatcher RoundRobinLoadBalancingStrategy上。

因此,如果您有多个订阅者使用同一个DirectChannel,则会在round-robin中将消息发送给他们。

您的用例需要为每个远程服务器配置10 <int-sftp:outbound-channel-adapter>。并对<channel>属性使用相同的简单channel定义。

<int-file:inbound-channel-adapter>应始终使用默认round-robin策略将其消息发送到该共享频道。

相关问题