请告诉我如何从子目录中递归获取文件?
我添加了一个表达式来选择一个远程目录到我的 IntegrationFlow - String fileNameRegex = "(\d {4} | Success | Error |. *. Xml)"; ftp.inboundStreamingAdapter(模板())。远程目录(新的 ValueExpression <> (fileNameRegex))
但这不起作用,文件仅从根目录中获取。
目录结构如下:
/
1111/
In/
Out/
Error/
Success/
2222/
In/
Out/
Error/
Success/
我只需要从 Error 和 Success *.xml 获取文件
@Bean
public DelegatingSessionFactory<FTPFile> delegatingSessionFactory() {
Map<Object, SessionFactory<FTPFile>> factories = new LinkedHashMap<>();
for (int i = 0; i < this.names.length; i++) {
DefaultFtpSessionFactory factory = new DefaultFtpSessionFactory();
factory.setHost(this.hosts[i]);
factory.setUsername(this.users[i]);
factory.setPassword(this.pwds[i]);
factories.put(this.names[i], factory);
}
return new DelegatingSessionFactory<>(factories, factories.values().iterator().next());
}
@Bean
public RotatingServerAdvice advice() {
List<RotationPolicy.KeyDirectory> keyDirectories = new ArrayList<>();
keyDirectories.add(new RotationPolicy.KeyDirectory(this.names[0], ""));
keyDirectories.add(new RotationPolicy.KeyDirectory(this.names[1], ""));
return new RotatingServerAdvice(delegatingSessionFactory(), keyDirectories);
}
@Bean
public FtpRemoteFileTemplate template() {
return new FtpRemoteFileTemplate(delegatingSessionFactory());
}
@Bean
public IntegrationFlow ftpIntegrationFlow() {
String fileNameRegex = "(\\d{4}|Success|Error|.*.xml)";
return IntegrationFlows.from(
Ftp.inboundStreamingAdapter(template()).remoteDirectory(new ValueExpression<>(fileNameRegex)),
e -> e.poller(Pollers.fixedDelay(500).advice(advice())))
.transform(new StreamTransformer("UTF-8"))
.handle(message -> {
log.info("Read file: {}", message.getHeaders()
.get("file_remoteDirectory" + "/" + message.getHeaders()
.get("file_remoteFile")));
messageService.unmarshall(message);
})
.get();
}