Another common pattern among all enterprise integration patterns is to have a pausable entity. In the case of Akka, we might want to do this in order to make sure that an actor has finished processing one message before receiving another. We can easily create another actor to accomplish this thanks to two features: become/unbecome and stash/unstash. Become/unbecome lets us change the behavior of an actor at runtime. Stash/unstash lets us save messages in an internal queue to later put them back into the mailbox. Then, this new actor will act as a proxy in front of your actor to deliver messages one by one only.
The pausable actor pattern
Getting ready
To step through this recipe, we need to import the Hello-Akka project; all other prerequisites are the same...