Reputation: 33
Akka-Cluster module is used for clustering within the application.
If we have a setup where an entity actor (we may have hundreds of actors distributed across nodes) running on a node is scheduled to receive message every 1 min, (using Timers/Scheduler) , What happens when the node that is hosting the actor shutsdown gracefully and ungracefully
How can we ensure that entity actor gets created on the other node automatically. Will the entity actor gets created only upon receiving the first message or will the actor gets created automatically without any logic in the application. Also, what happens to the scheduler of the actor. Can the scheduler be run automatically on the actor post migration to other node.. Note as of now I was not planning to use persistence ? but will it help to have persistance for automatic entity creation and scheduling of messages
Upvotes: 0
Views: 286
Reputation: 20551
If the entity actors are managed using cluster sharding, you can use remember entities to automatically keep entities alive until the entity passivates itself. In kubernetes or similar environments where there's no reliable persistent storage attached to the instance, this does need Akka Persistence under the hood.
If not using cluster sharding, then you'd probably have to implement similar functionality using persistence.
Note that after a rebalance, the state of the entity actor is not recovered unless the entity actor is persistent in some way (e.g. by itself being event-sourced using Akka Persistence). This state would include the timer state. The entity actor gets recreated (most typically using Behaviors.setup
(I forget if the Java API uses that name)), so depending on what the actor should do in response to that message:
if "every minute" means "not more than once per minute", then the entity actor should just start scheduling for every minute as part of its setup; if the crash/rebalance happened 59 seconds after the last scheduled message, there will be a gap, but if the message results in, e.g., polling some external resource, the gap might not, in the end, matter.
if "every minute" means "at least once per minute", then the entity actor can immediately send the scheduled message to itself as well as set the timer. Then if the crash/rebalance happened immediately after the last scheduled message, there'll be a shorter than normal period between the effects of the scheduled messages, but there won't be multi-minute gaps.
Upvotes: 1