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

Transfer files on different servers (sftp) using Spring Integration

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

顺序无关紧要,重要的是每个服务器都应该相等 load.I 我对 Spring 集成相当陌生,但我找到了一个使用 SI[=13= 执行文件 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>

round-robin 隐藏在 DirectChannel 中,UnicastingDispatcher 隐藏在 RoundRobinLoadBalancingStrategy 中。

因此,当您有多个订阅者订阅同一个 DirectChannel 时,消息将在 round-robin.

中发送给他们

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

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