我想递归地列出远程目录及其子目录中的文件。我知道可以通过调用 ListGateway 的 listFiles 方法来做到这一点:列表列表 = listGateway.listFiles("/ussama/providers")@MessagingGatewaypublic 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;}@Beanpublic IntegrationFlow sftpOutboundListFlow() { return IntegrationFlows.from("listSftpChannel") .handle(new SftpOutboundGateway(sftpSessionFactory(), "ls", "payload") ).get();}但我想每隔 x 分钟做一次。有没有办法可以轮询远程目录以在每 x 分钟后列出文件。请给java配置。
1 回答

紫衣仙女
TA贡献1839条经验 获得超15个赞
轮询目录的简单 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可以方便地创建端点。
添加回答
举报
0/150
提交
取消