Creating a ScatterGatherFirstCompletedPool of actors
In this recipe, we will learn about the ScatterGatherFirstCompletedPool
of actors. Eponymously it sends the same message to all the actors, waits for the actor who first completes the work, and sends a response to it. It then discards replied from the other actors.
Getting ready
- Create a Scala file,
ScatterGatherFirstCompletedpool.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.ScatterGatherFirstCompletedPool import akka.util.Timeout import scala.concurrent.Await import scala.concurrent.duration
- Create an example actor as follows:
class ScatterGatherFirstCompletedPoolActor extends Actor { override def receive = { case msg: String => sender ! "I say hello back to you" case _ => println(s" I don't understand...