骆驼:从同一目录读取和写入

时间:2019-07-02 18:51:46

标签: java file apache-camel integration

我有这条骆驼路线:

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

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

谢谢!

1 个答案:

答案 0 :(得分:3)

该文件很可能在目标目录中被覆盖,但是在完成后,将其移至.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();