Reputation: 4540
How can I only load an actor if it has previously been formally created following domain rules? Everything I've seen using actorOf
and persistence always creates an empty instance and then applies the [possibly empty] set of events that have occurred, whereas I would prefer to make empty instances unrepresentable. Is there a standard approach for requiring a "created" event and otherwise triggering failure via "not found"?
My thinking is to have one actor instance for each entity in the system, but my expectation is that less than 10% of the entities will be actively needed at any given time so I'm trying to avoid loading the entire set just to check validity when handling a request.
I'm new to Akka and event sourcing in general so if I'm thinking about things from an unhelpful perspective I'm open to any alternatives as well.
Upvotes: 1
Views: 192
Reputation: 49
I guess you are talking about PersistentActors.
There is no api for pre persisting state outside of the PersistentActor. The idea is that actor keeps track of his state for himself. There is no profit of empty actors, actors should keep some state so when you initialise it via actorOf
it should have kind of state Created
. On the other hand you should not think it has saved its state until it reports to creator that it was persisted.
Persistent actors are loaded passively into the memory only when you initialise them explicitly, so all the entities won't be loaded at startup. If you want to passivate them you can stop the actors or invoke setReceiveTimeout
method on actor's context.
Upvotes: 1