retort v2.7.0 Retort.Server.Generic behaviour View Source

Exposes an Ecto.Schema.t as a JSONAPI resource over JSON RPC on a RabbitMQ queue.

Any code with side-effects, such as Logger or Repo calls should stay in this module. Any pure functions that write back to the Retort.Server.Generic.RPC.t can be in Retort.Server.Generic.RPC.

Link to this section Summary

Types

t()
  • callback - The module that implement this behaviour and its own internal state.
  • channel - the AMQP channel connected to queue
  • queue - name of RabbitMQ queue to consume

Functions

Most received messages filter through here to find the right function to call based on RPC method

Sets connection, channel, and queue to Rabbit

Attaches consumer to queue in t

Callbacks

Should match on rpc.decoded.method and return rpc with rpc.response.decoded.result set

Link to this section Types

Link to this type t() View Source
t() :: %Retort.Server.Generic{callback: Retort.Server.Generic.Callback.t(), channel: %AMQP.Channel{conn: term(), pid: term()} | nil, queue: String.t()}
  • callback - The module that implement this behaviour and its own internal state.
  • channel - the AMQP channel connected to queue
  • queue - name of RabbitMQ queue to consume

Link to this section Functions

Link to this function handle_info(msg, state) View Source
handle_info({:DOWN, reference(), :process, pid(), any()}, t()) :: {:noreply, t()}
handle_info({:basic_deliver, any(), any()}, t()) :: {:noreply, t()}
handle_info({:basic_consume_ok, %{:consumer_tag => any(), optional(term()) => term()}}, t()) :: {:noreply, t()}
handle_info({:basic_cancel_ok, %{:consumer_tag => any(), optional(term()) => term()}}, t()) :: {:noreply, t()}
handle_info({:basic_cancel, %{:consumer_tag => any(), optional(term()) => term()}}, t()) :: {:stop, :normal, t()}

Most received messages filter through here to find the right function to call based on RPC method.

Link to this function init(args) View Source
init(t()) ::
  {:ok, t()} |
  {:stop, any()} |
  {:ok, t(), :hibernate | :infinity | non_neg_integer()}

Sets connection, channel, and queue to Rabbit

Link to this function start_link(state, gen_server_options \\ []) View Source
start_link(t(), GenServer.options()) :: GenServer.on_start()

Attaches consumer to queue in t

Link to this section Callbacks

Link to this callback handle_method(rpc, callback_state) View Source
handle_method(rpc :: Retort.Server.Generic.RPC.t(), callback_state :: any()) :: Retort.Server.Generic.RPC.t()

Should match on rpc.decoded.method and return rpc with rpc.response.decoded.result set.

Link to this callback init(generic_state, callback_state) View Source
init(generic_state :: t(), callback_state) ::
  {:ok, callback_state} |
  {:ok, callback_state, timeout() | :hibernate} |
  :ignore |
  {:stop, reason :: any()} when callback_state: any()