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

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/2 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/2

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, %{connection: conn} = state) do
    SomeImpl.publish(conn, payload, state.options)
  end 
end

Summary

Types

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 resolution() :: :ok | :error | {:ok, term()} | {:error, any()}

Callback resolution

Callbacks

@callback config() :: [connections: keyword(), channels: 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(arg1, payload)

View Source
@callback handle_publish(
  (pid() -> resolution()) | %{message: term()} | term(),
  Finitomata.State.payload()
) :: resolution()

The callback to be implemented by the consumer of this code

@callback on_fatal(Finitomata.id(), %{
  payload: any(),
  message: String.t(),
  retries: non_neg_integer()
}) ::
  :ok

The callback to be called when retries exhausted