Creating a SmallestMailboxPool of actors
In this recipe, you will learn how to create a SmallestMailboxPool
or group for actors. SmallestMailboxPool
is a pool of actors, and resembles the property whereby messages will globally be delivered to the actor with the least number of messages in its mailbox.
Getting ready
To step through this recipe, you will have to import the Hello-Akka
project in an IDE such as IntelliJ Idea, and create a package called chapter3
.
How to do it...
- Create a Scala file,
Smallestmailbox.scala
, in the packagecom.packt.chapter3.
- Add the following imports at the top of the file:
import akka.actor.{Props, ActorSystem, Actor} import akka.routing.SmallestMailboxPool
- Let's define an actor as follows:
class SmallestmailboxActor extends Actor { override def receive = { case msg: String => println(s" I am ${self.path.name}") case _ => println(s" I don't understand the message") } }
- Let's create...