View Source Rambla.Handler behaviour (Rambla v1.2.5)

Default handler for AMQP connections.

use Rambla.Handler

When you use Rambla.Handler, the Rambla.Handler module will do the following things for your module:

  • implement @behaviour Finitomata.Pool.Actor where actor/2 will delegate to handle_publish/3 expected to be implemented by this module, and overridable on_result/2 and on_error/2 will have a reasonable default implementation (debug for the former and warn and retry for the latter)
  • set @behaviour Rambla.Handler to invite you to implement real publishing handler as handle_publish/3

Example

defmodule Rambla.Handler.Some do
  use Rambla.Handler

  @impl Rambla.Handler
  def config do
    [
      connections: [
        local_conn: [url: "amqp://guest:guest@localhost:5672"],
      ],
      channels: [
        chan_1: [connection: :local_conn]
      ]
    ]
  end

  @impl Rambla.Handler
  def handle_publish(payload, options, %{connection: conn} = state) do
    SomeImpl.publish(conn, payload, options)
  end 
end

Summary

Types

The callback function to be passed to Rambla.publish/3

The channel name

The connection name

The allowed callback resolution

Callbacks

The callback to get to the configuration

If specified, these services will be started before pools under :rest_for_one

The callback to be implemented by the consumer of this code

The callback to be called when retries exhausted

Types

@type callback() ::
  ([source: module(), destination: term(), options: map()] -> resolution())

The callback function to be passed to Rambla.publish/3

@type channel_name() :: atom()

The channel name

@type connection_name() :: atom()

The connection name

@type resolution() :: :ok | :error | {:ok, term()} | {:error, any()}

The allowed callback resolution

Callbacks

@callback config() :: [
  connections: [{connection_name(), keyword() | binary()}],
  channels: [
    {channel_name(), connection: connection_name(), options: keyword()}
  ]
]

The callback to get to the configuration

@callback external_servers(Finitomata.Pool.id()) :: [
  {module(), [any()]} | Supervisor.child_spec()
]

If specified, these services will be started before pools under :rest_for_one

Link to this callback

handle_publish(payload, options, state)

View Source
@callback handle_publish(
  payload :: callback() | %{message: term()} | term(),
  options :: map(),
  state :: Finitomata.State.payload()
) :: resolution()

The callback to be implemented by the consumer of this code

@callback on_fatal(
  Finitomata.id(),
  {nil
   | (any() ->
        :ok
        | :retry
        | {:retry,
           %{optional(:retries) => non_neg_integer(), optional(:pid) => pid()}}),
   %{payload: any(), message: String.t(), retries: non_neg_integer()}}
) :: :ok

The callback to be called when retries exhausted