Search documentation of macula

# macula_rpc_router (macula v0.44.2)

View Source

RPC call routing strategies. Selects which provider to use for a call (local or remote).

# Summary

## Types

provider_info/0
registration/0
router_state/0
strategy/0

## Functions

new_state(Strategy)

Create new router state.

select_local(Rest)

Select local handler (returns first one).

select_provider(_, LocalHandlers, RemoteProviders)

Select provider using stateless strategy. For local_first, random, and closest strategies.

select_provider_closest(LocalNodeId, LocalHandlers, RemoteProviders)

Select provider using closest strategy (requires local node ID).

select_provider_stateful(State, LocalHandlers, RemoteProviders)

Select provider using stateful strategy (for round_robin).

select_remote_random(Providers)

Select random remote provider.

# Types

# provider_info/0

    -type provider_info() :: macula_rpc_dht:provider_info().

# registration/0

    -type registration() :: macula_rpc_registry:registration().

# router_state/0

    -type router_state() :: #{strategy := strategy(), round_robin_index := non_neg_integer()}.

# strategy/0

    -type strategy() :: local_first | round_robin | random | closest.

# Functions

# new_state(Strategy)

    -spec new_state(strategy()) -> router_state().

Create new router state.

# select_local(Rest)

    -spec select_local([registration()]) -> {ok, registration()} | not_found.

Select local handler (returns first one).

# select_provider(_, LocalHandlers, RemoteProviders)

    -spec select_provider(strategy(), [registration()], [provider_info()]) ->
                             {local, registration()} | {remote, provider_info()} | {error, no_provider}.

Select provider using stateless strategy. For local_first, random, and closest strategies.

# select_provider_closest(LocalNodeId, LocalHandlers, RemoteProviders)

    -spec select_provider_closest(binary(), [registration()], [provider_info()]) ->
                                     {local, registration()} |
                                     {remote, provider_info()} |
                                     {error, no_provider}.

Select provider using closest strategy (requires local node ID).

# select_provider_stateful(State, LocalHandlers, RemoteProviders)

    -spec select_provider_stateful(router_state(), [registration()], [provider_info()]) ->
                                      {{local, registration()} |
                                       {remote, provider_info()} |
                                       {error, no_provider},
                                       router_state()}.

Select provider using stateful strategy (for round_robin).

# select_remote_random(Providers)

    -spec select_remote_random([provider_info()]) -> {ok, provider_info()} | not_found.

Select random remote provider.