【问题标题】:Camel: Read and Write from the same directoryCamel:从同一目录读取和写入
【发布时间】:2019-11-13 11:00:29
【问题描述】:

我有这条骆驼路线:

final String URI_FILE = "file:{{PATH}}";
final String POOLER = "&scheduler=quartz2&scheduler.cron=0+0/10+*+*+*+?";

from(URI_FILE + POOLER)
.pollEnrich().simple("{{URL_CHECKER}}",String.class).aggregationStrategy(new myEstratey())
.choice()
    .when(exchangeProperty("CONTINUE").isEqualTo(true))
        .log("Condition was met")
        .to(URI_DIRECT) //To another route
     .endChoice()
     .otherwise()
        .log("I'll try again later")
        .to(URI_FILE) 
.endChoice();

我想每 10 分钟PATH 读取一个文件,然后使用 pollEnrich 检查条件。如果满足条件,则路由继续。在另一种情况下,我想将文件返回到同一目录 (PATH)。

这条路线运行正常,甚至显示日志消息“我会稍后再试”,但之后,文件就消失了,没有返回到 PATH

发生了什么?骆驼不允许这样做吗?

谢谢!!

【问题讨论】:

    标签: java file apache-camel integration


    【解决方案1】:

    该文件很可能在目标目录中被覆盖,但是在完成后,它被移动到.camel 目录。

    这是预期行为,请参阅File component docs

    任何移动或删除操作都在(发布命令)路由完成后执行


    更好的回滚你的路由,它会默认将文件保存在源目录中。

    final String URI_FILE = "file:{{PATH}}";
    final String POOLER = "&scheduler=quartz2&scheduler.cron=0+0/10+*+*+*+?";
    
    from(URI_FILE + POOLER)
    .pollEnrich().simple("{{URL_CHECKER}}",String.class).aggregationStrategy(new myEstratey())
    .choice()
        .when(exchangeProperty("CONTINUE").isEqualTo(true))
            .log("Condition was met")
            .to(URI_DIRECT) //To another route
         .endChoice()
         .otherwise()
            .log("I'll try again later")
            .rollback() // rollback processing and keep file in original directory
    .endChoice();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-24
      • 2018-11-01
      • 2017-05-01
      • 2016-01-28
      • 2019-11-21
      • 2020-02-20
      相关资源
      最近更新 更多