retort v2.1.0 Retort.Server.Generic behaviour

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.

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

Types

t()
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

Functions

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

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

init(args)
init(t) ::
  {:ok, t} |
  {:stop, any} |
  {:ok, t, :hibernate | :infinity | non_neg_integer}

Sets connection, channel, and queue to Rabbit

start_link(state, gen_server_options \\ [])

Attaches consumer to queue in t

Callbacks

handle_method(rpc, callback_state)
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.

init(generic_state, callback_state)
init(generic_state :: t, callback_state) ::
  {:ok, callback_state} |
  {:ok, callback_state, timeout | :hibernate} |
  :ignore |
  {:stop, reason :: any} when callback_state: any