Elixir MOM v0.5.3 MOM.RPC

Gateway adapter for RPC.

Creates a command and a response channel, which has to be connected to a RPC processor.

It also has Method Caller lists to call directly and can be chained

Options:

  • context — Use the given context, if none, creates one
  • method_caller: [mc|nil|false] — Use the given method caller, if nil create one, false dont use.

method_caller: false is needed when connecting with an endpoint that provides all method calling, for example a remote side.

Example of use

It can be used in a blocking fasion

iex> alias MOM.{Message, Channel, RPC}
iex> {:ok, rpc} = RPC.start_link
iex> {:ok, caller} = RPC.Endpoint.Caller.start_link(rpc)
iex> Channel.subscribe(rpc.request, fn msg ->
...>  Channel.send(rpc.reply, %Message{ payload: msg.payload.params, id: msg.id })
...>   :ok
...>   end, front: true) # dirty echo rpc.
iex> RPC.Endpoint.Caller.call(caller, "echo", "Hello world!")
{:ok, "Hello world!"}

Returns {:error, :unkown_method} when method does not exist

iex> alias MOM.RPC
iex> {:ok, rpc} = RPC.start_link
iex> {:ok, caller} = RPC.Endpoint.Caller.start_link(rpc)
iex> RPC.Endpoint.Caller.call(caller, "echo", "Hello world!")
{:error, :unknown_method}

dir is a method caller functionality, so no method caller, no dir.

iex> alias MOM.RPC
iex> {:ok, rpc} = RPC.start_link method_caller: false
iex> {:ok, caller} = RPC.Endpoint.Caller.start_link(rpc)
iex> RPC.Endpoint.Caller.call(caller, "dir", [])
{:error, :unknown_method}

Summary

Functions

Joins two RPC channels, to create networks

Stops the server

Taps into the channels

Functions

chain(left, right)

Joins two RPC channels, to create networks.

From left to right, any request on the right side may be done on the right side (if nobody replied it before). Replies from right to left.

start_link(options \\ [])
stop(rpc, reason \\ :normal)

Stops the server

tap(rpc, name \\ nil)

Taps into the channels