Spring integration 通过Spring集成从远程SFTP目录和子目录进行流式传输

Spring integration 通过Spring集成从远程SFTP目录和子目录进行流式传输,spring-integration,spring-integration-dsl,spring-integration-sftp,Spring Integration,Spring Integration Dsl,Spring Integration Sftp,我正在使用SpringIntegrationStreamingInboundChannel适配器,从远程SFTP获取流,并解析每一行内容进程 我使用: IntegrationFlows.from(Sftp.inboundStreamingAdapter(template) .filter(remoteFileFilter) .remoteDirectory("test_dir"),

我正在使用SpringIntegrationStreamingInboundChannel适配器,从远程SFTP获取流,并解析每一行内容进程

我使用:

IntegrationFlows.from(Sftp.inboundStreamingAdapter(template)
                          .filter(remoteFileFilter)
                          .remoteDirectory("test_dir"),
                        e -> e.id("sftpInboundAdapter")
                              .autoStartup(true)
                              .poller(Pollers.fixedDelay(fetchInt)))
                .handle(Files.splitter(true, true))
....
现在它可以工作了。但我只能从
test_dir
目录中获取文件,但我需要递归地从这个dir和子目录中获取文件,并解析每一行

我注意到,
入站通道适配器
,它是
Sftp.inboundAdapter(sftpSessionFactory).scanner(…)
。它可以扫描子目录。但是我没有看到
流式入站通道适配器的任何内容

那么,如何在
流式入站通道适配器中实现“从目录递归获取文件”


谢谢。

您可以使用两个出站网关-第一个做
ls-R
(递归列表);拆分结果并使用配置了
mget-stream
的网关来获取每个文件

编辑

@springboot应用程序
公共类SO60987851应用程序{
公共静态void main(字符串[]args){
SpringApplication.run(So60987851Application.class,args);
}
@豆子
集成流(SessionFactory csf){
返回IntegrationFlows.from(()->“foo”,e->e.poller(Pollers.fixedDelay(5_000)))
.handle(Sftp.outboundGateway(csf,Command.LS,“有效载荷”)
.options(Option.RECURSIVE,Option.NAME_仅限)
//需要一个更健壮的元数据存储来实现持久性,除非删除文件
.filter(新的SFtpersistentAcceptonceFileListFilter(新的SimpleMetadataStore(),“测试”))
.split()
.log()
.enrichHeaders(headers->headers.headerExpression(“fileToRemove”,“foo/”+payload”))
.handle(Sftp.outboundGateway(csf,Command.GET,“'foo/”+有效负载”)
.options(Option.STREAM))
.split(新文件拆分器())
.log()
//我们可以删除远程文件而不是筛选器。
//但是需要一些逻辑来等待,直到所有的行都被读取
//.handle(Sftp.outboundGateway(csf,Command.RM,“headers['fileToRemove']))
//.log()
.get();
}
@豆子
CachingSessionFactory csf(默认SFTPSessionFactory sf){
返回新的CachingSessionFactory(sf);
}
@豆子
DefaultSftpSessionFactory sf(){
DefaultSftpSessionFactory sf=新的DefaultSftpSessionFactory();
sf.setHost(“10.0.0.8”);
sf.setUser(“gpr”);
setPrivateKey(新文件系统资源(新文件(“/Users/grussell/.ssh/id_rsa”));
sf.SetAllowunknowkeys(真);
返回sf;
}
}

您可以使用两个出站网关-第一个做
ls-R
(递归列表);拆分结果并使用配置了
mget-stream
的网关来获取每个文件

编辑

@springboot应用程序
公共类SO60987851应用程序{
公共静态void main(字符串[]args){
SpringApplication.run(So60987851Application.class,args);
}
@豆子
集成流(SessionFactory csf){
返回IntegrationFlows.from(()->“foo”,e->e.poller(Pollers.fixedDelay(5_000)))
.handle(Sftp.outboundGateway(csf,Command.LS,“有效载荷”)
.options(Option.RECURSIVE,Option.NAME_仅限)
//需要一个更健壮的元数据存储来实现持久性,除非删除文件
.filter(新的SFtpersistentAcceptonceFileListFilter(新的SimpleMetadataStore(),“测试”))
.split()
.log()
.enrichHeaders(headers->headers.headerExpression(“fileToRemove”,“foo/”+payload”))
.handle(Sftp.outboundGateway(csf,Command.GET,“'foo/”+有效负载”)
.options(Option.STREAM))
.split(新文件拆分器())
.log()
//我们可以删除远程文件而不是筛选器。
//但是需要一些逻辑来等待,直到所有的行都被读取
//.handle(Sftp.outboundGateway(csf,Command.RM,“headers['fileToRemove']))
//.log()
.get();
}
@豆子
CachingSessionFactory csf(默认SFTPSessionFactory sf){
返回新的CachingSessionFactory(sf);
}
@豆子
DefaultSftpSessionFactory sf(){
DefaultSftpSessionFactory sf=新的DefaultSftpSessionFactory();
sf.setHost(“10.0.0.8”);
sf.setUser(“gpr”);
setPrivateKey(新文件系统资源(新文件(“/Users/grussell/.ssh/id_rsa”));
sf.SetAllowunknowkeys(真);
返回sf;
}
}

我不熟悉spring integration,是否有这样的例子?我在回答中添加了一个例子。我不熟悉spring integration,是否有这样的例子?我在回答中添加了一个例子。