2016-04-28 31 views
1

SIのアプリケーションを構築し、ファイルの1000からなる入力ディレクトリを読み取り、リモートサーバー、たとえばプロセッサインスタンスのある10台のサーバーにコピーする必要があります。処理のためにそれらを拾います。ファイルの移動は、ラウンドロビン方式でなければならないので、処理中にサーバーに負担がかからないようにしてください。もう少し詳しく説明すると、入力ディレクトリに10個のファイルがあるとすると、アプリケーションはserver1のファイル 1をコピーし、サーバ2のファイルfile2 をコピーする必要があります。 。 。 .... ファイル10のサーバー10Spring Integrationを使用して別のサーバー(sftp)にファイルを転送する

シーケンスは重要ではありません。すべてのサーバーの負荷が同じである必要があります。私はSpring Integrationにはかなり新しいですが、ファイルのsftpを実行するサンプルが見つかりました。 SI

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

round-robinRoundRobinLoadBalancingStrategyUnicastingDispatcherDirectChannelに隠されています。

したがって、同じDirectChannelに複数の加入者がいる場合は、メッセージはround-robinに送信されます。

あなたのユースケースに必要なものは、リモートサーバーごとに10 <int-sftp:outbound-channel-adapter>を設定するだけです。また、channel属性に同じ簡単な<channel>定義を使用します。

<int-file:inbound-channel-adapter>は、そのメッセージをその共有チャネルにデフォルトのround-robin戦略で送信する必要があります。

+0

@ Artem Bilan - suggetionに感謝します。私はDirect Channelについて読んで、あなたが言ったことが真実であるようです[link](http://docs.spring.io/spring-integration/reference/html/messaging-channels-section.html#channel-implementations-directchannel)このアプローチの唯一の問題は、コードを変更する必要があるリストから新しいサーバーを削除または追加するたびに、事前にサーバーの数を知っておく必要があることです。 –

+0

申し訳ありませんが、あなたの懸念事項では分かりません。 'DirectChannel'(とそのUnicastingDispatcher')は' subscribe/unsubscribe'関数に従って自動的に調整を行います。あなたの質問の問題について、いくつかの「有罪なコード」を共有してもよろしいですか? –

+0

私はsftp用に私の設定を追加しました。 。 –

関連する問題