【问题标题】:Camel log error骆驼日志错误
【发布时间】:2017-06-20 21:48:30
【问题描述】:

我使用 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

【问题讨论】:

  • 附注仅当文件非常小时将文件内容“转换”为字符串

标签: scala apache-camel dsl


【解决方案1】:

自以为是的答案..

恕我直言,您应该尝试使用骆驼作为声明性语言。我总是觉得 '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,了解处理错误的不同方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    相关资源
    最近更新 更多