# `RpcLoadBalancer`
[🔗](https://github.com/MikaAK/rpc_load_balancer/blob/main/lib/rpc_load_balancer.ex#L1)

Distributed RPC load balancer built on `:pg`.

Acts as a per-instance Supervisor that starts the caches and GenServer
needed for a single load balancer. Also provides the public API for
node selection, RPC calls/casts, and low-level `:erpc` wrappers.

## Starting a load balancer

    RpcLoadBalancer.start_link(
      name: :my_lb,
      selection_algorithm: RpcLoadBalancer.LoadBalancer.SelectionAlgorithm.RoundRobin,
      algorithm_opts: [weights: %{node() => 1}]
    )

# `name`

```elixir
@type name() :: atom()
```

# `call`

```elixir
@spec call(node(), module(), atom(), [any()], keyword()) :: ErrorMessage.t_res(any())
```

# `call_on_random_node`

```elixir
@spec call_on_random_node(String.t(), module(), atom(), [any()], keyword()) ::
  ErrorMessage.t_res(any())
```

# `cast`

```elixir
@spec cast(node(), module(), atom(), [term()], keyword()) ::
  :ok | {:error, ErrorMessage.t()}
```

# `cast_on_random_node`

```elixir
@spec cast_on_random_node(String.t(), module(), atom(), [any()], keyword()) ::
  :ok | {:error, ErrorMessage.t()}
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `get_members`

```elixir
@spec get_members(name()) :: {:ok, [node()]} | {:error, ErrorMessage.t()}
```

# `select_node`

```elixir
@spec select_node(
  name(),
  keyword()
) :: {:ok, node()} | {:error, ErrorMessage.t()}
```

# `start_link`

```elixir
@spec start_link(keyword()) :: Supervisor.on_start()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
