A random pool of actors does nothing more than send messages to a randomly picked routee among a list of routees. It is useful when you don't care which routee picks up the message and does the work for you, and it may be the case that you end up sending the message to the busiest actor.
All prerequisites are the same as in previous recipes; just import the Hello-Akka
project and start.
- Create a Scala file,
RandomPool.scala
, incom.packt.chapter3
.
- Add the following import to the top of the file:
import akka.actor.{Props, ActorSystem, Actor} import akka.routing.RandomPool
- Define an actor as follows:
class RandomPoolActor extends Actor { override def receive = { case msg: String => println(s" I am ${self.path.name}") case _ => println(s" I don't understand the message") } }
- Create a test application as follows:
object RandomPoolApp extends...