Sending specially handled messages to routers
There are some kinds of message that are specially handled by actors. They have a special behavior. These messages are mostly used for handling management of the actors.
The following are the different types of message:
Broadcast
messagesPoisonPill
messagesKill
messages- Management messages such as
AddRoutee
,RemoveRoutee
, and so on
Getting ready
We will limit our recipe to the Broadcast
, PoisonPill
, and Kill
messages. All prerequisites are the same as earlier.
How to do it...
- Create a Scala file,
SpeciallyHandled.scala
, in the packagecom.packt.chapter3
. - Add the following import to the top of the file:
import akka.actor.{PoisonPill, Props, ActorSystem, Actor} import akka.routing.{Broadcast, RandomPool}
- Add the following case object message sent to the actor:
case object Handle
- Define an actor as follows:
class SpeciallyHandledActor extends Actor { override def receive = { case Handle => println...