Usually what you want in that case is to subscribe to ClusterEvent.MemberUp
, which current actor will receive, once new node will become part of the cluster.
Example of actor handling this kind of event:
class MyActor : ReceiveActor
{
private readonly Cluster cluster = Cluster.Get(Context.System);
public MyActor()
{
Receive<ClusterEvent.MemberUp>(memberUp => memberUp.Member.Address == cluster.SelfAddress, memberUp =>
{
// handle current node up
});
}
protected override void PreStart()
{
cluster.Subscribe(Self, new []{ typeof(ClusterEvent.MemberUp)});
}
protected override void PostStop()
{
cluster.Unsubscribe(Self);
base.PostStop();
}
}
In this case memberUp => memberUp.Member.Address == cluster.SelfAddress
is additional filter for the handler which means, that it will be handled only, when current node, this actor resides on, will join the cluster. Up events send from other nodes will be ignored.