Registers system wide services.
Each service/2 macro registers system-wide service and function with
documentation in module that uses this module.
servicep/2 is considered as private service and is not introduced to other nodes
in the cluster.
Service functions invoke function of the same name of specified module.
If result of that invocation is {:reply, %X3m.System.Message{}},
it sends message to message.reply_to pid.
If result of invocation is :noreply, nothing is sent to that pid.
In any case function returns :ok.
Examples
Defining router
defmodule MyRouter do
use X3m.System.Router
@servicedoc false
service :create_user, MessageHandler
@servicedoc """
overridden!
"""
service :get_user, MessageHandler
service :edit_user, MessageHandler
servicep :private_service, MessageHandler
endWhen defining a router you can pass :ensure_local_logging? argument in
options which is expected to be boolean().
This argument is optional and if not passed is treated as true thus
ensuring logs of the called node are not shown on the calling node.
When this argument is passed as false, log messages sent to stdout by the called node
will be shown in the caller node stdout, thus keeping REPL behaviour is maintained.
Examples
Defining router ensuring remote callers don't receive logger stdout
defmodule MyRouter do
use X3m.System.Router
...
end
is identical to
defmodule MyRouter do
use X3m.System.Router
...
endDefining router with default logger behaviour
defmodule MyRouter do
use X3m.System.Router, ensure_local_logging?: false
...
endGetting registered services (public, private, or by default all)
iex> MyRouter.registered_services()
[create_user: 1, get_user: 1, edit_user: 1, private_service: 1]
iex> MyRouter.registered_services(:public)
[create_user: 1, get_user: 1, edit_user: 1]Invoking service as a function
iex> :create_user |>
...> X3m.System.Message.new() |>
...> MyRouter.create_user()
:ok