X3m.System.Router (X3m System v0.7.19) View Source

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
end

Getting 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

Link to this section Summary

Link to this section Functions

Link to this macro

service(service_name, message_handler)

View Source (macro)
Link to this macro

service(service_name, message_handler, f)

View Source (macro)
Link to this macro

servicep(service_name, message_handler)

View Source (macro)
Link to this macro

servicep(service_name, message_handler, f)

View Source (macro)