【问题标题】:Akka Scala Camel. Exception handling阿卡斯卡拉骆驼。异常处理
【发布时间】:2016-05-24 00:06:08
【问题描述】:

我有akka camel-ftp 消费者。我想处理代码中的所有异常(例如身份验证异常,或无法读取 ftp 上的文件)。我只能在日志中看到堆栈跟踪,无法处理。 也许使用scalaz-camel 会更好。

另外我想知道什么时候所有文件都被处理并且 Actor 空闲直到下一次读取 ftp 文件夹

class FtpWorkerActor() extends Consumer with ActorLogging {

  override def receive: Actor.Receive = {
    case msg: CamelMessage => /* handle files */

    case v: Any => /*never riched. but i need to understand if I have authentification issues etc*/

  }

  override def endpointUri: String = {
    val initDelay = 1000 // 1 second
    val otherOptions = s"disconnect=true&throwExceptionOnConnectFailed=true&filter=#datFileFilter&delay=$processingDelay&initialDelay=$initDelay"
    s"ftp://$username@$ftpSourcePath?username=$username&password=$pass&$otherOptions"
  }
}

【问题讨论】:

    标签: scala apache-camel akka scalaz akka-camel


    【解决方案1】:

    您应该尝试在主管中运行您的 Actor 并在那里实现错误处理。以下是有关此的更多文档:http://doc.akka.io/docs/akka/current/scala/fault-tolerance.html

    在这种情况下,您的主管将能够捕获所有异常并决定如何处理 FtpWorkerActor - 停止、重新启动等。

    【讨论】:

    • 你好@sap1ens。谢谢你的回答。我将override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 2, withinTimeRange = 1 minute) { case v:GenericFileOperationFailedException => log.warning(v.getMessage) Restart case _: Exception ⇒ Restart } 添加到经理演员。但它不起作用。我可以在日志中看到 GenericFileOperationFailedException 被骆驼 ftp 标记为警告(不是错误)。你能分享更多细节吗
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    • 1970-01-01
    • 2019-06-15
    • 1970-01-01
    相关资源
    最近更新 更多