使用MongoDb-Gridfs组件处理错误

时间:2017-09-06 11:38:43

标签: apache-camel

当使用 mongodb-gridfs 组件处理上传的文件到MongoDb数据库时,组件将字段驼峰处理设置为字符串"已完成&# 34。

我希望在发生错误时设置此字段,但下面的路线仍设置"完成"值。

我在这里缺少什么?

from('mongodb-gridfs:mongoClient?database=DEMO&queryStrategy=FileAttribute')
   .process{ throw new RuntimeCamelException()}
   .to('file:mongo')

更新1:

我已尝试过以下路线 - 捕获了异常,但是"驼峰处理"仍然设置为"完成"。

onException(RuntimeCamelException.class).to("file://mongoerror")

from('mongodb-gridfs:mongoClient?database=DEMO&queryStrategy=FileAttribute')
   .process{ throw new RuntimeCamelException()}
   .to('file://mongo')

1 个答案:

答案 0 :(得分:0)

我认为你应该尝试在骆驼环境中自定义 Error Handling 。 然后,您可以定义触发错误时所需的行为。

您还可以使用 Exception Clause

以下是文档中的示例:

onException(ValidationException.class).to("activemq:validationFailed");

from("seda:inputA").to("validation:foo/bar.xsd", "activemq:someQueue");

from("seda:inputB").to("direct:foo").to("rnc:mySchema.rnc","activemq:anotherQueue");