There are some situations when you want your actor to process a certain message first before any other message, at any point of time. This means that you can tell an actor to do some particular work before doing any other job.

Akka Cookbook
By :

There are some situations when you want your actor to process a certain message first before any other message, at any point of time. This means that you can tell an actor to do some particular work before doing any other job.
To step through this recipe, we need to import our Hello-Akka project in IDE-like IntelliJ Idea. Prerequisites are the same as those of the previous recipes.
import akka.dispatch.ControlMessage
import akka.actor.{Props, Actor, ActorSystem}
case object MyControlMessage extends ControlMessage
class Logger extends Actor {
def receive = {
case MyControlMessage => println("Oh, I have to process
Control message first")
case x => println(x.toString)
}
}
control-aware-dispatcher {
mailbox-type =
"akka.dispatch.UnboundedControlAwareMailbox"
//Other dispatcher configuration goes here
}
object ControlAwareMailbox extends App {
val actorSystem = ActorSystem("HelloAkka")
val actor =
actorSystem.actorOf(Props[Logger].withDispatcher(
"control-aware-dispatcher"))
actor ! "hello"
actor ! "how are"
actor ! "you?"
actor ! MyControlMessage
}
Oh, I have to process Control message first
hello
how are
you?
In step three, we create an object, MyControlMessage, which extends the ControlMessage.
ControlMessage is a trait. The message which extends this trait will be handled on priority by ControlAwareMailbox. ControlAwareMailbox maintains two queues to allow messages that extend ControlMessage to be delivered with priority.
In step four, we create an actor which will handle ControlMessage.
In step five, we configure the control-aware-dispatcher in application.conf.
In step six. we create the actor with control-aware-dispatcher.
In step seven, we are able to see in the output that the actor processed ControlMessage first.