Actors talking with each another

The earlier snippet showed how a nonactor code used the asked pattern. The upcoming snippet shows how an actor asks another for some service.

We have two actors. Actor1 receives an Actor2 reference in its constructor. When Actor1 receives a string message, it delegates the message to Actor2.

The Actor2 message processing simulates a delay of one second and then upcases the argument string and returns it back as shown in the following:

package{Actor, ActorLogging, ActorRef, ActorSystem, Props}import akka.pattern.askimport akka.util.Timeoutimport scala.concurrent.{Await, Future}import scala.concurrent.duration._import scala.util.{Failure, Success}import scala.concurrent.ExecutionContext.Implicits. ...

Get Concurrent Patterns and Best Practices now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.