Camel Log Error

I am using scala camel dsl and I need to catch exceptions.

My pipeline does not register anything in the case of 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}"))
    }

How to correctly catch exceptions with scala dsl? And how to specify a rollback strategy? I do not want him to repeat in the event of a failure.

The only little bad example I found: https://svn.apache.org/repos/asf/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TryCatchFinallyTest .scala

+4
source share
1 answer

Opinion...

IMHO, you should try and use a camel as a declarative language. I always find "try ... catch" dsl too mandatory

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")

}

.

+2

Source: https://habr.com/ru/post/1668746/


All Articles