我使用scala camel dsl,我需要捕获异常。
我的管道没有在handle
案例中记录任何内容:
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
答案 0 :(得分:2)
意见回答..
恕我直言,您应该尝试使用驼峰作为声明性语言。我总是找到'try ... catch'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,了解处理错误的不同方法。