MeshxRpc.Client behaviour (MeshxRpc v0.1.0) View Source

Convenience module on top of MeshxRpc.Client.Pool.

Module leverages Kernel.use/2 macro to simplify user interaction with MeshxRpc.Client.Pool module:

  • current module name is used as pool id,
  • pool options can be specified with use/2 clause.

Please refer to MeshxRpc.Client.Pool documentation for details.

Example RPC client module:

# lib/client.ex
defmodule Example1.Client do
  use MeshxRpc.Client,
    address: {:tcp, {127, 0, 0, 1}, 12_345},
    telemetry_prefix: [:example1, __MODULE__],
    pool_opts: [size: 20, max_overflow: 5],
    idle_reconnect: 60 * 60 * 1000

  def echo(args), do: call(:echo, args)
end

Start with application supervisor:

# lib/example1/application.ex
def start(_type, _args) do
  Supervisor.start_link([Example1.Client],
    strategy: :one_for_one,
    name: Example1.Supervisor
  )
end

Run RPC calls:

iex(1)> Example1.Client.echo("hello world")
"hello world"
iex(2)> Example1.Client.call(:echo, "hello world")
"hello world"
iex(3)> MeshxRpc.Client.Pool.call(Example1.Client, :echo, "hello world")
"hello world"

Link to this section Summary

Callbacks

Makes a synchronous RPC call request to the server and waits for its reply.

Same as call/5, will reraise remote exception locally.

Sends an asynchronous RPC cast request to the server.

Returns a specification to start a RPC client workers pool under a supervisor.

Link to this section Callbacks

Link to this callback

call(request, args, timeout, retry, retry_sleep)

View Source (optional)

Specs

call(
  request :: atom(),
  args :: list(),
  timeout :: timeout(),
  retry :: pos_integer(),
  retry_sleep :: non_neg_integer()
) :: term() | {:error_rpc, reason :: term()}

Makes a synchronous RPC call request to the server and waits for its reply.

Link to this callback

call!(request, args, timeout, retry, retry_sleep)

View Source (optional)

Specs

call!(
  request :: atom(),
  args :: list(),
  timeout :: timeout(),
  retry :: pos_integer(),
  retry_sleep :: non_neg_integer()
) :: term() | {:error_rpc, reason :: term()}

Same as call/5, will reraise remote exception locally.

Link to this callback

cast(request, args, timeout, retry, retry_sleep)

View Source (optional)

Specs

cast(
  request :: atom(),
  args :: list(),
  timeout :: timeout(),
  retry :: pos_integer(),
  retry_sleep :: non_neg_integer()
) :: :ok

Sends an asynchronous RPC cast request to the server.

Link to this callback

child_spec(opts)

View Source (optional)

Specs

child_spec(opts :: Keyword.t()) :: Supervisor.child_spec()

Returns a specification to start a RPC client workers pool under a supervisor.