How libcluster works: Topologies and Supervisors
mainTo use libcluster, you define one or more topologies. A topology consists of a chosen strategy and its associated configuration.
To activate clustering, you must start the Cluster.Supervisor module within your application's supervision tree, passing the list of topologies to it. The supervisor manages the lifecycle of the clustering processes based on your defined topologies.
defmodule MyApp.App do
use Application
def start(_type, _args) do
topologies = [
example: [
strategy: Cluster.Strategy.Epmd,
config: [hosts: [:"a@127.0.0.1", :"b@127.0.0.1"]],
]
]
children = [
{Cluster.Supervisor, [topologies, [name: MyApp.ClusterSupervisor]]},
# ..other children..
]
Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
end
end