我使用
scala camel dsl,我需要捕获异常.
我的管道没有记录句柄中的任何内容:
s"$ftpSource"
.log("File is received")
.as(classOf[String])
.attempt{
process(failingProcessor)
}.handle(classOf[Exception]) apply {
process((exchange: Exchange) => logger.error(s"Error during file reading: ${exchange.in.toString}"))
}
如何使用scala dsl正确捕获异常?以及如何指定回滚策略?我不希望它在失败的情况下重试.
我发现的唯一一个小的可怜的例子是:
https://svn.apache.org/repos/asf/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TryCatchFinallyTest.scala
最佳答案 意见回答..
恕我直言,你应该尝试使用骆驼作为声明性语言.我总觉得’尝试……捕捉’dsl太迫切了
以下是使用更具声明性的异常处理程序的示例
handle[MyException] {
log("handling exception")
process((e : Exchange) => e.in = "an error occured")
}.handled
"jetty:http://localhost:9091/service" ==> {
id ("some-error-route")
log("processing request")
process((e : Exchange) => e.in = e.in[String].reverse)
process((_: Exchange) => throw new MyException("Something went wrong"))
log("done")
}
我建议您查看优秀的书籍Camel In action以了解处理错误的不同方法.