macula_cluster_static (macula v0.20.5)
View SourceMacula 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
-spec add_node(atom()) -> ok.
Add a node to the cluster configuration.
Add a node to a named instance.
-spec get_connected() -> [atom()].
Get the list of currently connected nodes.
Get the list of connected nodes from a named instance.
-spec get_nodes() -> [atom()].
Get the list of configured nodes.
Get the list of configured nodes from a named instance.
-spec remove_node(atom()) -> ok.
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.
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
-spec stop() -> ok.
Stop the static cluster strategy.
Stop a named static cluster strategy.