Creating actors

Once an actor is defined, the Actor instance needs to be created and started. All actors are created in the context of an actor system or another actor. As part of the actor creation itself, the actor gets started. Before it starts accepting and processing messages, the actor can implement a method called preStart, which can handle any initialization required by the actor:

Creating actors

To create an actor, Akka provides a construct called Props. Props is a configuration class, which takes in the actor along with the various configurations that need to be applied to it.

Actor with default constructor

Let's first take an example of creating an

Get Akka Essentials now with O’Reilly online learning.

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