0

I have akka camel-ftp consumer. I would like to handle all exceptions in code (e.g. Authentification Exception, or file on ftp cannot be read). I can see stacktrace in logs only and cannot handle it. Maybe it is better to use scalaz-camel.

Additionally I would like to know when all files are processed and Actor idle untill next read ftp folder

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"
  }
}
Alex S
  • 11
  • 3

1 Answers1

0

You should try to run your Actor inside a supervisor and implement error handling there. Here's more documentation about that: http://doc.akka.io/docs/akka/current/scala/fault-tolerance.html

In this case your supervisor will be able to catch all exceptions and decide what to do with the FtpWorkerActor - stop, restart, etc.

sap1ens
  • 2,877
  • 1
  • 27
  • 30
  • Hello @sap1ens. Thank you for the answer. I added `override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 2, withinTimeRange = 1 minute) { case v:GenericFileOperationFailedException => log.warning(v.getMessage) Restart case _: Exception ⇒ Restart } ` to the manager actor. but it doesn't work. I can see in log GenericFileOperationFailedException marked as warn (not error) by camel ftp. could you share some more details – Alex S May 24 '16 at 13:26