macula_cluster_static (macula v0.20.5)

View Source

Macula Static Cluster Strategy.

A simple cluster formation strategy that connects to a predefined list of nodes. Equivalent to libcluster's Cluster.Strategy.Epmd.

Configuration

Start with a list of nodes to connect to:

   {ok, _Pid} = macula_cluster_static:start_link(#{
       nodes => ['node1@host1', 'node2@host2', 'node3@host3'],
       reconnect_interval => 5000  %% ms, default 5000
   }).

Or from environment variables:

   %% CLUSTER_NODES=node1@host1,node2@host2,node3@host3
   {ok, _Pid} = macula_cluster_static:start_link(#{}).

Behavior

- Attempts to connect to all configured nodes on startup - Monitors connected nodes for disconnect events - Automatically reconnects to disconnected nodes - Ignores self-connection attempts - Logs connection/disconnection events

Callbacks

Register a callback module to receive cluster events:

   {ok, _Pid} = macula_cluster_static:start_link(#{
       nodes => [...],
       callback => self()  %% PID or {Module, Function}
   }).
   %% Receives: {macula_cluster, nodeup, Node}
   %% Receives: {macula_cluster, nodedown, Node}

Summary

Functions

Add a node to the cluster configuration.

Add a node to a named instance.

Get the list of currently connected nodes.

Get the list of connected nodes from a named instance.

Get the list of configured nodes.

Get the list of configured nodes from a named instance.

Remove a node from the cluster configuration.

Remove a node from a named instance.

Start the static cluster strategy with default options.

Start the static cluster strategy with options.

Stop the static cluster strategy.

Stop a named static cluster strategy.

Functions

add_node(Node)

-spec add_node(atom()) -> ok.

Add a node to the cluster configuration.

add_node(NameOrPid, Node)

-spec add_node(atom() | pid(), atom()) -> ok.

Add a node to a named instance.

get_connected()

-spec get_connected() -> [atom()].

Get the list of currently connected nodes.

get_connected(NameOrPid)

-spec get_connected(atom() | pid()) -> [atom()].

Get the list of connected nodes from a named instance.

get_nodes()

-spec get_nodes() -> [atom()].

Get the list of configured nodes.

get_nodes(NameOrPid)

-spec get_nodes(atom() | pid()) -> [atom()].

Get the list of configured nodes from a named instance.

remove_node(Node)

-spec remove_node(atom()) -> ok.

Remove a node from the cluster configuration.

remove_node(NameOrPid, Node)

-spec remove_node(atom() | pid(), atom()) -> ok.

Remove a node from a named instance.

start_link()

-spec start_link() -> {ok, pid()} | {error, term()}.

Start the static cluster strategy with default options.

start_link(Opts)

-spec start_link(map()) -> {ok, pid()} | {error, term()}.

Start the static cluster strategy with options.

Options: - nodes: List of node atoms to connect to - reconnect_interval: Milliseconds between reconnect attempts (default 5000) - callback: PID or {Module, Function} to receive cluster events

stop()

-spec stop() -> ok.

Stop the static cluster strategy.

stop(NameOrPid)

-spec stop(atom() | pid()) -> ok.

Stop a named static cluster strategy.