2016-05-23 77 views
0

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

此外,我想知道,当所有的文件处理和演员闲置,直到下一次读的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://[email protected]$ftpSourcePath?username=$username&password=$pass&$otherOptions" 
    } 
} 

回答

0

你应该尝试运行主管内的演员和执行错误处理在那里。下面是有关的更多文档:http://doc.akka.io/docs/akka/current/scala/fault-tolerance.html

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

+0

你好@ sap1ens。谢谢你的答案。我加入'重写VAL supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 2,withinTimeRange = 1分钟){ 情况ν:GenericFileOperationFailedException => log.warning(v.getMessage) 重启 情况下_:异常⇒重启 } '到经理演员。但它不起作用。我可以在日志中看到GenericFileOperationFailedException由骆驼ftp标记为警告(而不是错误)。你能分享一些更多细节吗? –