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

cre*_*ijn 2 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");
Run Code Online (Sandbox Code Playgroud)

如果在ServiceBean中引发错误,则该文件将复制到错误文件夹,但它也会保留在out目录中.

回滚的最佳方法是什么?

谢谢

Cla*_*sen 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");
Run Code Online (Sandbox Code Playgroud)

而不是存储在路线中,然后只需使用移动选项,它就变成了

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