繁体   English   中英

如何从子目录中递归获取文件spring-integration

[英]How to get files recursively from subdirectories spring-integration

请告诉我如何从子目录中递归获取文件?

我将一个表达式添加到 select 一个远程目录到我的 IntegrationFlow - String fileNameRegex = "(\d {4} | Success | Error |. *. Xml)"; Ftp.inboundStreamingAdapter(模板())。 远程目录(新的 ValueExpression <> (fileNameRegex))

但这不起作用,文件仅从根目录中获取。

目录结构如下:

/
1111/
    In/
    Out/
    Error/
    Success/

2222/
    In/
    Out/
    Error/
    Success/

我只需要从 Error and 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();
}

尚不支持: https://github.com/spring-projects/spring-integration/issues/3407

从根目录中看不到这些深层文件。 您必须将特定子目录的通道适配器配置为工作根。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM