リモートディレクトリとそのサブディレクトリにもファイルを再帰的にリストしたいと思います。ListGatewayのlistFilesメソッドを次のように呼び出すことでこれを実行できることを私は知っています。
リストリスト= listGateway.listFiles( "/ ussama / provider")
@MessagingGateway
public interface ListGateway {
@Gateway(requestChannel = "listSftpChannel")
List<File> listFiles(String dir);
}
@Bean
@ServiceActivator(inputChannel = "listSftpChannel")
public MessageHandler handler() {
SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sftpSessionFactory(), "ls", "'/directory'");
return sftpOutboundGateway;
}
@Bean
public IntegrationFlow sftpOutboundListFlow() {
return IntegrationFlows.from("listSftpChannel")
.handle(new SftpOutboundGateway(sftpSessionFactory(), "ls", "payload")
).get();
}
しかし、私はx分ごとにそれをやりたいです。x分ごとにリモートディレクトリをポーリングしてファイルを一覧表示する方法はありますか?PlzはJava構成を提供します。
ディレクトリの単純なPOJOメッセージソースをポーリングし、必要に応じてポーラーを構成します...
@Bean
public IntegrationFlow pollLs(SessionFactory<LsEntry> sessionFactory) {
return IntegrationFlows.from(() -> "foo/bar", e -> e
.poller(Pollers.fixedDelay(5, TimeUnit.SECONDS)))
.handle(Sftp.outboundGateway(sessionFactory, Command.LS, "payload")
.options(Option.RECURSIVE))
.handle(System.out::println)
.get();
}
明らかに.handle
、List<LsEntry>
結果を受け取るには、で何らかのサービスが必要になります。
ちなみに、Sftp
エンドポイントを作成するための便利なメソッドを持つファクトリクラスがあります。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加