How it works...
In this recipe, we covered how to create a persistent actor. To achieve that, we need to mix in the PersistentActor trait. Our scenario simulates an actor that holds information about active users. To begin, we need to define events, commands, and state. State is the class that represents the current state of the actor and what we want to be able to recover. In our case, we have ActiveUsers. Events represent the changes happening to the state, in our case, AddUser and RemoveUser. Commands represent the regular messages sent to the actor, in our case, UserUpdate. Each persistent actor needs to define a persistenceId, a receiveRecover, and a receiveCommand behavior. The persistence ID needs to be an identifier that uniquely ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access