KantanCluster (kantan_cluster v0.3.1) View Source

Form a simple Erlang cluster easily in Elixir.

Link to this section Summary

Types

A node type. See Node.start/3.

Options for a cluster.

Functions

Broadcasts message on a given topic across the whole cluster.

Connects current node to specified nodes.

Disconnects current node from speficied nodes.

Starts a node and attempts to connect it to specified nodes. Configuration options can be specified as an argument

Stops a node and all the connections.

Subscribes the caller to a given topic.

See KantanCluster.PubSub.unsubscribe/1.

Link to this section Types

Specs

node_type() :: :longnames | :shortnames

A node type. See Node.start/3.

Specs

option() ::
  {:node, binary() | {node_type(), node()}}
  | {:cookie, atom()}
  | {:connect_to, node() | [node()]}

Options for a cluster.

  • :node
    • the name of a node that you want to start
    • default: {:longnames, :"xxxx@yyyy.local"} where xxxx is a random string, yyyy is the hostname of a machine
    • examples:
      • "node1"
      • {:longnames, :"node1@nerves-mn00.local"}
      • {:shortnames, :"node1@nerves-mn00"}
  • :cookie
  • :connect_to
    • a list of nodes we want our node to be connected with
    • default: []

Link to this section Functions

Link to this function

broadcast(topic, message)

View Source

Specs

broadcast(binary(), any()) :: :ok | {:error, any()}

Broadcasts message on a given topic across the whole cluster.

  • topic - The topic to broadcast to, ie: "users:123"
  • message - The payload of the broadcast

Specs

connect(node() | [node()]) :: {:ok, [pid()]}

Connects current node to specified nodes.

Specs

disconnect(node() | [node()]) :: :ok

Disconnects current node from speficied nodes.

Specs

start([option()]) :: :ok

Starts a node and attempts to connect it to specified nodes. Configuration options can be specified as an argument

KantanCluster.start(
  node: "node1",
  cookie: :hello,
  connect_to: [:"nerves@nerves-mn00.local"]
)

or in your config/config.exs.

config :kantan_cluster,
  node: "node1",
  cookie: :hello,
  connect_to: [:"nerves@nerves-mn00.local"]

Specs

stop() :: :ok | {:error, :not_allowed | :not_found}

Stops a node and all the connections.

Specs

subscribe(binary()) :: :ok | {:error, any()}

Subscribes the caller to a given topic.

  • topic - The topic to subscribe to, for example: "users:123"

Specs

unsubscribe(binary()) :: :ok

See KantanCluster.PubSub.unsubscribe/1.