The following code example (which you can copy and run) shows a MyParentActor that creates a MyChildActor.
The MyChildActor throws an exception for its first message which causes it to be restarted. However, what I want to achieve is for "Message 1" to still be processed before "Message 2" on restart of the MyChildActor. Instead, what is happening is that Message 1 is added to the tail of the mailbox queue, and so Message 2 is processed first. How do I achieve ordering of the original messages on restart of an actor, without having to create my own mailbox etc? http://stackoverflow.com/questions/37683586/akka-message-ordering-after-akka-restart object TestApp extends App { var count = 0 val actorSystem = ActorSystem() val parentActor = actorSystem.actorOf(Props(classOf[MyParentActor])) parentActor ! "Message 1" parentActor ! "Message 2" class MyParentActor extends Actor with ActorLogging{ var childActor: ActorRef = null @throws[Exception](classOf[Exception]) override def preStart(): Unit = { childActor = context.actorOf(Props(classOf[MyChildActor])) } override def receive = { case message: Any => { childActor ! message } } override def supervisorStrategy: SupervisorStrategy = { OneForOneStrategy() { case _: CustomException => Restart case _: Exception => Restart } } } class MyChildActor extends Actor with ActorLogging{ override def preRestart(reason: Throwable, message: Option[Any]): Unit = { message match { case Some(e) => self ! e } } override def receive = { case message: String => { if (count == 0) { count += 1 throw new CustomException("Exception occurred") } log.info("Received message {}", message) } } } class CustomException(message: String) extends RuntimeException(message) } -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
