【问题标题】:Read a datestamped file from an FTP server everyday using Camel每天使用 Camel 从 FTP 服务器读取带日期戳的文件
【发布时间】:2015-06-15 15:28:15
【问题描述】:

我每天都在尝试从 FTP 服务器读取带日期戳的文件,例如 16:15。为了了解如何执行此操作,我尝试连接到 FTP 服务器,每分钟一次,每次都增加文件号。

目前我写的代码是:

private String readFtp = "quartz2://exchange/readFtp?cron=";
private String cronExpression = "1 * * * * ?";

private int i=0;

@Override
public void configure() throws Exception {
    from(readFtp+cronExpression).process(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {

            System.out.println("Triggered the process");

            from(getFtpServerUrl())
                    .bean(RateServiceImpl.class, "update")
                    .log("Downloaded file ${file:name} complete.");
        }
    });
}

private String getFtpServerUrl() {

    i++;
    System.out.println("Here with i=" + i);
    return String.format("ftp://%s:21/%s?username=%s&password=%s&fileName=%s", ftpServer, ftpPath, ftpUsername, ftpPassword, "rate"+i+".xml");
}

当我运行它时,它每分钟打印一次"Triggered the process"。它也调用getFtpServerUrl

它没有调用RateServiceImpl.update。它没有记录"Downloaded file ${file:name} complete."

  • 我是不是走错了路?
  • 有没有更简单的方法来构造每分钟的文件名?
  • 为什么不调用RateServiceImpl.update

【问题讨论】:

    标签: java apache-camel camel-ftp


    【解决方案1】:

    你这样做是错误的。要从处理器添加路由,您需要将路由添加到camelContext,而不是使用父类RouteBuilder,这是错误的。

    ftp 使用者已内置对 cron 表达式的支持,因此您可以将其配置为每天下午 4:15 运行。然后你需要使用文件过滤器来过滤它找到的文件,并且只选择你想要的文件。

    过滤器记录在

    这里的cron也有点

    我写了一篇关于它的博客

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-13
      • 2013-10-03
      相关资源
      最近更新 更多