How to start queue processing after cluster is formed

Hi,

In my app, I need to tell a QueueProcessor actor to start processing queue events after the cluster is formed and processing result will be sent to persistent actors. At the moment, I start queue processing after the following code, which I think it is not appropriate:

// Akka Management hosts the HTTP routes used by bootstrap
AkkaManagement(system).start()

// Starting the bootstrap process needs to be done explicitly
ClusterBootstrap(system).start()

I am thinking two possible ways:

  • ClusterBootstrap(system).start() returns a Future telling the result of bootstrap, but this is not offered.
  • Listening to cluster formed event, which I don’t know which one I should listen to? Shall I listen to ClusterEvent.LeaderChanged and judge based on whether leader is empty or not?

Please help me out. Thanks.

Cheng

Could you use a Start message to tell the actor to begin processing of the queue? The message shouldn’t be delivered to the actor before the system is ready.

Or you could use Become/Unbecome, perhaps via similar mechanism (a message).

The registerOnMemberUp callback mechanism is probably a good solution for you.

https://doc.akka.io/docs/akka/current/cluster-usage.html#how-to-startup-when-cluster-size-reached

It does start processing before cluster is ready. It looks as soon as actor system is ready, you can send message to actors.

Thanks @TimMoore This looks like a good option. I will have a try.