【问题标题】:Moving files to archive directory using apache camel ftp component使用 apache camel ftp 组件将文件移动到存档目录
【发布时间】:2021-10-06 06:12:14
【问题描述】:

我在数据库中存储的文件很少,这些文件是从 FTP 服务器获取并处理的。

我正在尝试将这些文件移动到 FTP 服务器上的存档目录,为此我正在使用 producerTemplate

这是我到目前为止所做的。

try {
    DefaultCamelContext camelContext = new DefaultCamelContext();
    ProducerTemplate template = camelContext.createProducerTemplate();
    template.request("ftp://xxxxx/include=fileFromDb.xml&move=archive/fileFromDb.xml", outExchange -> {
        String body = outExchange.getIn().getBody(String.class);                    
    });
} catch (Exception ex) {
    // update the status in database to indicate archive failed
}

但这失败并出现以下错误,无法解决。

WARN  o.a.c.c.f.remote.RemoteFileProducer - Writing file failed with: Cannot write null body to file: archive/ID-192-168-1-113-tpgi-com-au-1627667653835-1-2

我已经尝试从其他答案中实施解决方案,但它们都没有奏效。

如果我像下面这样编写自定义路由,它可以正常工作,但因为我需要执行我更喜欢使用生产者模板的移动后操作。

from("ftp://xxxxx/include=fileFromDb.xml&move=archive/fileFromDb.xml")
    .log("file moved successfully").

【问题讨论】:

    标签: spring apache-camel camel-ftp


    【解决方案1】:

    如果我像下面这样编写自定义路由,它可以正常工作,但因为我需要执行我更喜欢使用生产者模板的移动后操作。

    您可以使用 onCompletion 调用另一个路由来处理移动后操作。

    String sftpURI = "sftp:localhost:2222/upload" +
    "?username="+username+"&password="+password
    + "&move=done";
    
    String sftpPostMoveURI = "sftp:localhost:2222/upload/done" +
    "?username="+username+"&password="+password
    + "&fileName=${headers.CamelFileName}";
    
    from(sftpURI)
        .routeId("ReadFileUsingSFTPRoute")
        .onCompletion().onCompleteOnly()
            .setBody().constant("")
            .to("direct:postMoveActions")
        .end()
        .log("file ${headers.CamelFileName} moved");
    
    from("direct:postMoveActions")
        .routeId("PostMoveActionsRoute")
        .log("doing post move actions!")
        .pollEnrich().simple(sftpPostMoveURI).timeout(5000)
        .log("File: ${body}");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-06
      • 1970-01-01
      相关资源
      最近更新 更多