macula (macula v1.4.23)

View Source

Macula SDK — Public API for mesh applications.

This is the main entry point for applications using the Macula SDK. All functions delegate to macula_mesh_client or macula_multi_relay for relay mesh communication.

Summary

Functions

Advertise an RPC procedure handler.

Call a remote procedure (default 5s timeout).

Call a remote procedure with timeout.

Call a remote procedure on a specific target node (default 5s timeout).

Call a remote procedure on a specific target node with timeout.

Connect to a Macula relay.

Disconnect from the relay.

Ensure this node is running in distributed mode.

Get the Erlang cluster cookie.

Join the Macula relay mesh with Erlang distribution.

List all nodes connected to the relay (default 5s timeout).

List all nodes connected to the relay with options.

Subscribe to node up/down events.

Publish an event to a topic (fire-and-forget).

Publish an event with options.

Resolve a mesh name to node identity information.

Set the Erlang cluster cookie.

Subscribe to a topic.

Stop advertising a procedure.

Unsubscribe from node up/down events.

Unsubscribe from a topic.

Types

client/0

-type client() :: pid().

procedure/0

-type procedure() :: binary().

topic/0

-type topic() :: binary().

Functions

advertise(Client, Procedure, Handler)

-spec advertise(client(), procedure(), fun()) -> {ok, reference()} | {error, term()}.

Advertise an RPC procedure handler.

advertise(Client, Procedure, Handler, Opts)

-spec advertise(client(), procedure(), fun(), map()) -> {ok, reference()} | {error, term()}.

Advertise with options.

call(Client, Procedure, Args)

-spec call(client(), procedure(), term()) -> {ok, term()} | {error, term()}.

Call a remote procedure (default 5s timeout).

call(Client, Procedure, Args, Timeout)

-spec call(client(), procedure(), term(), pos_integer()) -> {ok, term()} | {error, term()}.

Call a remote procedure with timeout.

call_node(Client, Target, Procedure, Args)

-spec call_node(client(), binary(), procedure(), term()) -> {ok, term()} | {error, term()}.

Call a remote procedure on a specific target node (default 5s timeout).

Target can be a mesh name, site_id, or node_id (all binaries). The relay resolves the target and routes the CALL directly to that node.

call_node(Client, Target, Procedure, Args, Timeout)

-spec call_node(client(), binary(), procedure(), term(), pos_integer()) ->
                   {ok, term()} | {error, term()}.

Call a remote procedure on a specific target node with timeout.

connect(Url, Opts)

-spec connect(binary() | [binary()], map()) -> {ok, client()} | {error, term()}.

Connect to a Macula relay.

Returns a client PID (macula_mesh_client gen_server) that you pass to all other API functions. Accepts a single URL binary or a list.

disconnect(Client)

-spec disconnect(client()) -> ok.

Disconnect from the relay.

ensure_distributed()

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

Ensure this node is running in distributed mode.

get_cookie()

-spec get_cookie() -> atom().

Get the Erlang cluster cookie.

join_mesh(Opts)

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

Join the Macula relay mesh with Erlang distribution.

After calling this, standard OTP distribution works across firewalls. Options: relays (required list), realm, identity, site, tls_verify.

list_nodes(Client)

-spec list_nodes(client()) -> {ok, map()} | {error, term()}.

List all nodes connected to the relay (default 5s timeout).

list_nodes(Client, Opts)

-spec list_nodes(client(), map()) -> {ok, map()} | {error, term()}.

List all nodes connected to the relay with options.

monitor_nodes()

-spec monitor_nodes() -> ok.

Subscribe to node up/down events.

publish(Client, Topic, Data)

-spec publish(client(), topic(), term()) -> ok.

Publish an event to a topic (fire-and-forget).

publish(Client, Topic, Data, Opts)

-spec publish(client(), topic(), term(), map()) -> ok.

Publish an event with options.

resolve(Client, Name)

-spec resolve(client(), binary()) -> {ok, map()} | {error, term()}.

Resolve a mesh name to node identity information.

Returns the node's identity including name, site_id, city, endpoint, and connected_at timestamp. Works for names, site_ids, or node_ids.

set_cookie(Cookie)

-spec set_cookie(atom() | binary()) -> ok.

Set the Erlang cluster cookie.

subscribe(Client, Topic, Callback)

-spec subscribe(client(), topic(), fun((term()) -> ok) | pid()) -> {ok, reference()} | {error, term()}.

Subscribe to a topic.

The callback receives the event payload (map or binary). Returns a subscription reference for unsubscribing.

unadvertise(Client, Procedure)

-spec unadvertise(client(), procedure()) -> ok | {error, term()}.

Stop advertising a procedure.

unmonitor_nodes()

-spec unmonitor_nodes() -> ok.

Unsubscribe from node up/down events.

unsubscribe(Client, SubRef)

-spec unsubscribe(client(), reference()) -> ok | {error, term()}.

Unsubscribe from a topic.