View Source KantanCluster (kantan_cluster v0.4.0)

Form a simple Erlang cluster easily in Elixir.

Link to this section Summary

Types

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.

Unsubscribes the caller from a given topic.

Link to this section Types

@type option() ::
  {:name, node()}
  | {:sname, node()}
  | {:cookie, atom()}
  | {:connect_to, node() | [node()]}

Options for a cluster.

  • :name
    • the fully-qualified name of a node that you want to start
    • examples:
      • :"node1@172.17.0.8"
  • :sname
    • the short name of a node that you want to start
    • examples:
      • :node1
      • :"node1@localhost"
  • :cookie
  • :connect_to
    • a list of nodes we want your node to be connected with
    • default: []

Link to this section Functions

Link to this function

broadcast(topic, message)

View Source
@spec 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
@spec connect(node() | [node()]) :: {:ok, [pid()]}

Connects current node to specified nodes.

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

Disconnects current node from speficied nodes.

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

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

KantanCluster.start(
  name: :"hoge@172.17.0.7",
  cookie: :mycookie,
  connect_to: [:"piyo@172.17.0.8"]
)

or in your config/config.exs.

config :kantan_cluster,
  name: :"hoge@172.17.0.7",
  cookie: :mycookie,
  connect_to: [:"piyo@172.17.0.8"]
@spec stop() :: :ok | {:error, :not_allowed | :not_found}

Stops a node and all the connections.

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

Subscribes the caller to a given topic.

  • topic - The topic to subscribe to, for example: "users:123"
@spec unsubscribe(binary()) :: :ok

Unsubscribes the caller from a given topic.