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
Link to this section Callbacks
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.
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.
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.
Specs
child_spec(opts :: Keyword.t()) :: Supervisor.child_spec()
Returns a specification to start a RPC client workers pool under a supervisor.