如何将文件移动到错误目录并使用apache camel回滚其他移动?

时间:2012-06-06 18:20:51

标签: apache-camel

首先:我是一个骆驼新手: - )

我想将文件从输入目录传输到输出目录并执行一些java操作。 如果出现问题,我想将文件移动到错误目录并回滚以移动到输出目录。

这是我在java dsl中的路线:

onException(Exception.class).handled(true).to("file://C:/temp/camel/error");
from("file://C:/temp/camel/in?delete=true").to("file://C:/temp/camel/out").bean(ServiceBean.class, "callWebservice");

如果在ServiceBean中抛出错误,该文件将被复制到错误文件夹,但它也会保留在out目录中。

回滚的最佳方式是什么?

由于

2 个答案:

答案 0 :(得分:7)

有一个moveFailed选项。只是使用它,那么你不需要onException等。 http://camel.apache.org/file2

from("file://C:/temp/camel/in?delete=true&moveFailed=C:/temp/camel/error")
  .to("file://C:/temp/camel/out")
  .bean(ServiceBean.class, "callWebservice");

而不是在路线中存储,只需使用移动选项,使其变为

from("file://C:/temp/camel/in?move=/temp/camel/out&moveFailed=/temp/camel/error")
  .bean(ServiceBean.class, "callWebservice");

答案 1 :(得分:0)

我认为你不能轻易'回滚'文件系统操作。也许你可以重新设计你的流程到第一个复制文件到一个中间'stage'目录,做你需要的工作,并根据工作结果移动文件到'output'或'error'目录。