We use one of these three approaches to transmit messages from one actor to another. As we've already established, tell
transmits messages and does not wait for the response; this way, we ensure at most once delivery. We can also use the ask
method in cases where we expect our called actors to respond back with some messages of the response type. There might be scenarios where you want to forward a message of a particular type with the same actor reference (ActorRef
) to another Actor. For this purpose, we can use the forward
method:
class AnotherActor extends Actor { override def receive = { case ShowFootballPlayersRequest(url) => { val playersInfoSource = Source.fromFile(url) val players = asPlayers(bufferedSourceToList(playersInfoSource)) players.foreach(player => println(player + "n")) } } } object AnotherActor { val props = Props[AnotherActor] }
We have defined AnotherActor
, and we can make...