Search documentation of macula

# macula_multi_relay (macula v0.44.2)

View Source

Multi-relay client — maintains N concurrent relay connections.

Wraps multiple macula_relay_client instances for node multi-homing. Subscribes and advertises on ALL connections. Publishes via PRIMARY. Deduplicates incoming messages by message_id (ring buffer).

On primary failure: promotes secondary, connects a new secondary. Same API as macula_relay_client for drop-in replacement.

Usage:

       Opts = #{relays => [R1, R2, R3, R4, R5],
                connections => 2,           %% default 2
                realm => <<"io.macula">>,
                identity => <<"my-node">>},
       {ok, Pid} = macula_multi_relay:start_link(Opts).

# Summary

## Functions

advertise(Pid, Procedure, Handler)
call(Pid, Procedure, Args, Timeout)
call_any(Pid, Procedure, Args, Timeout)

Try an RPC call on each connected relay in sequence. Returns the first successful result or the last error. Useful for cross-relay operations where the target may be on a different relay.

get_status(Pid)
handle_call(Request, From, State)
handle_cast(Msg, State)
handle_info(Info, State)
init(Opts)
publish(Pid, Topic, Payload)
start_link(Opts)
stop(Pid)
subscribe(Pid, Topic, Callback)
terminate(Reason, State)
unadvertise(Pid, Procedure)
unsubscribe(Pid, Ref)

# Functions

# advertise(Pid, Procedure, Handler)

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

# call(Pid, Procedure, Args, Timeout)

    -spec call(pid(), binary(), map(), timeout()) -> {ok, term()} | {error, term()}.

# call_any(Pid, Procedure, Args, Timeout)

    -spec call_any(pid(), binary(), map(), timeout()) -> {ok, term()} | {error, term()}.

Try an RPC call on each connected relay in sequence. Returns the first successful result or the last error. Useful for cross-relay operations where the target may be on a different relay.

# get_status(Pid)

    -spec get_status(pid()) -> {ok, map()}.

# handle_call(Request, From, State)

# handle_cast(Msg, State)

# handle_info(Info, State)

# init(Opts)

# publish(Pid, Topic, Payload)

    -spec publish(pid(), binary(), binary() | map()) -> ok.

# start_link(Opts)

# stop(Pid)

# subscribe(Pid, Topic, Callback)

    -spec subscribe(pid(), binary(), fun((map()) -> ok)) -> {ok, reference()}.

# terminate(Reason, State)

# unadvertise(Pid, Procedure)

    -spec unadvertise(pid(), binary()) -> ok.

# unsubscribe(Pid, Ref)

    -spec unsubscribe(pid(), reference()) -> ok.