Create a gen_server and call net_kernel:monitor_nodes(true) in the init method. Now the gen_server will receive {node_up, Node} and {node_down, Node} messages whenever a node joins or leaves the cluster.
A word of caution though, all the nodes will receive these notifications. So if only one node per cluster should be handling node_up and node_down notifications, that logic needs to be implemented on top of this gen_server.
1条答案
按热度按时间jckbn6z71#
Create a
gen_server
and callnet_kernel:monitor_nodes(true)
in theinit
method. Now thegen_server
will receive{node_up, Node}
and{node_down, Node}
messages whenever a node joins or leaves the cluster.A word of caution though, all the nodes will receive these notifications. So if only one node per cluster should be handling
node_up
andnode_down
notifications, that logic needs to be implemented on top of this gen_server.