【问题标题】:Apache Camel: How to download multiple files from SFTP with Premove, Move and MoveFailed options?Apache Camel:如何使用 Premove、Move 和 MoveFailed 选项从 SFTP 下载多个文件?
【发布时间】:2019-12-22 13:24:39
【问题描述】:

我有两个文件名,格式如下:

Gontagrator_1.xml
Gontagrator_2.xml

到目前为止,我只选择 Gontagrater_1.xml 并将其重命名为 processing 并在完成后失败。

 + "&fileName=" + sftpFileName
            + "&preMove="+sftpFileName+".$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.processing"
            + "&move="+sftpFileName+".$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}"
            + "&moveFailed="+sftpFileName+".$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.failed"

现在 Gontagrator_2 出现了。建议为两者创建单独的路线。

我们可以在一个路径中下载两者并相应地重命名吗?如果是,我需要传递什么值?

Update1:​​有多个文件名不同,但我只需要使用以上两个文件名

更新 2:来自组件的整体是:

    "{{m.protocol}}://{{m.hostname}}{{t.directory}}"
            + "?username={{m.username}}"
            + "&password={{m.password}}"
            + "&download=true"
            + "&useList=false"
            + "&stepwise=false"
            + "&disconnect=true"
            + "&passiveMode=true"
            + "&reconnectDelay=10000"
            + "&bridgeErrorHandler=true"
            + "&delay=30000"
            //+ "&fileName=" + sftpFileName
            + "&include="+ sftpFileName
            + "&preMove=$simple{file:onlyname}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.processing"
            + "&move=$simple{file:onlyname}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}"
            + "&moveFailed=$simple{file:onlyname}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.failed"
            + "&readLock=idempotent-changed"
            + "&idempotentRepository=#infinispan"
            + "&readLockRemoveOnCommit=true")
        .onException(GenericFileOperationFailedException.class)
            .onWhen(exchange -> { 
                    Throwable cause = exchange.getException(GenericFileOperationFailedException.class).getCause();
                    return (cause != null && cause.toString().equalsIgnoreCase("2: No such file"));
                }).handled(true)
                .logExhausted(true)
                .logExhaustedMessageHistory(true)
                 .log("Could not find file")
                .end()
        .log("Downloading xml file")
        //.to(archiveReceivedFile(sftpFileName))       
        .split(body().tokenizeXML("ERequest", "ERequests")).streaming()
            .inOnly(E_QUEUE)

【问题讨论】:

    标签: apache-camel integration spring-camel camel-ftp camel-http


    【解决方案1】:

    是的,您可以在一个路径中下载所有文件。

    你需要

    1. 删除fileName 选项(这样路由会选择所有文件)
    2. 使用file expression language (file:onlyname) 引用当前由 Camel SFTP 组件处理的文件名

      + "&preMove=$simple{file:onlyname}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.processing"
      + "&move=$simple{file:onlyname}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}"
      + "&moveFailed=$simple{file:onlyname}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.failed"
      
    3. 使用include 选项控制要拾取的文件(REGEX 匹配文件名模式)

      + "&include=Gontagrator_(1|2)\.xml"
      

    【讨论】:

    • 所以我将它作为 $simple{file:Gontagrator_1.xml, Gontagrator_2.xml} 传递。这种理解正确吗?我不希望它选择任何其他文件
    • 如果文件夹中有很多文件,但只想获取这两个文件(Gontagrator_1.xml 和 Gontagrator_2.xml),可以使用include 选项来限制文件被拾取按文件名模式
    • 看来正则表达式将是 -> "&include="+sftpFileName+"_*.xml" 其中 sftpFileName 将是 Gontagrator
    • useList改成true,需要list命令帮你在服务器上扫描
    • 对于文件名问题,也许您可​​以使用以下解决方法。在 movemoveFailed 两个选项中将 $simple{file:onlyname} 替换为 $simple{file:onlyname.noext}.xml
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-25
    • 2018-01-04
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多