If you want to send a message to all the actors who are dynamically created, you can use eventBus
I personally use system.eventStream for my business.
From the actor you can send to everyone:
context.system.eventStream.publish(StatisticsMessage())
or directly with the system.
The actor must subscribe to:
context.system.eventStream.subscribe
I continues from:
trait SubscriberActor extends Actor { def subscribedClasses: Seq[Class[_]] override def preStart() { super.preStart() subscribedClasses.foreach(this.context.system.eventStream.subscribe(this.self, _)) } override def postStop() { subscribedClasses.foreach(this.context.system.eventStream.unsubscribe(this.self, _)) super.postStop() } }
source share