Creating a TailChoppingPool of actors.
In this recipe, we will learn about the TailChoppingPool
of actors. TailChoppingPool
first sends the message to one, randomly picked, routee, and then, after a small delay, to a second routee (picked randomly from the remaining routees), and so on. It waits for the first reply it receives, and forwards it back to the original sender. Other replies are discarded.
Getting ready
- Create a Scala file,
TailChoppingpool.scala
, in the packagecom.packt.chapter3.
- Add the following imports at the top of the file:
import akka.actor.{Actor, ActorSystem, Props} import akka.pattern.ask import akka.routing.TailChoppingPool import akka.util.Timeout import scala.concurrent.Await import scala.concurrent.duration
- Create an example actor as follows:
class TailChoppingActor extends Actor { override def receive = { case msg: String => sender ! "I say hello back to you" ...