Apache Camel - 根据驼峰标题

时间:2018-01-18 13:17:48

标签: java apache-camel

我正在尝试创建一个路由设置:

  • 将文件从远程位置下载到"临时/暂存"夹
  • 对文件运行验证(处理器),根据Camel标题检查下载的文件的长度是否正确
  • 如果下载的文件长度正确
    • 将文件复制到目标目录
    • 将文件密钥添加到幂等存储库
  • 如果下载的文件长度不正确
    • 路线失败
    • 发送有关问题的电子邮件
    • 不要将文件密钥添加到idempotent存储库
    • 重试下载文件X次

到目前为止,我已经提出了以下哪些内容并不起作用,例如我不知道如何防止文件被记录为在幂等回购中检索到的...

这是在正确的轨道上吗? :

//Copy to staging as temp file
from(routeConfig.getFrom() + getCommonEndpointSettings())
        .routeId(routeConfig.getRouteId())
        // Grab the correct length of the remote file
        .setHeader(ORIGINAL_FILE_LENGTH, header(Exchange.FILE_LENGTH));

        // Exclude all files oder than the specified number of hours
        .filter(new FileModifiedSincePredicate(24))
        //Copy to staging folder for validation
        .to(routeConfig.getTo()+STAGING_FOLDER_NAME+"?fileName=${file:name}.temp")

        // Check the file size, throws exception if file size doesn't match
        .process(new FileSizeValidationProcessor() )
        // If we get here all is good and we can strip off the .temp file ending so the below route picks up the file
        .process(exchange -> {
             final String createdFileName = exchange.getIn().getHeader(Exchange.FILE_NAME_PRODUCED, String.class);
             final File createdFile = new File(createdFileName);
             log.info("Removing .temp file ending from " + createdFile.getAbsolutePath());
             createdFile.renameTo(new File(createdFile.getAbsolutePath().replace(".temp", "")));
         });


// Copy non .temp files from staging folder to destination folder        
from(routeConfig.getTo()+STAGING_FOLDER_NAME+"?delete=true&delay=30s&antExclude=*.temp")
        .routeId("Copy Staging " +routeConfig.getRouteId())
        .to(routeConfig.getTo())
        .end();

0 个答案:

没有答案