View Source Rambla.Handler behaviour (Rambla v1.1.0)
Default handler for AMQP connections.
use Rambla.Handler
When you
use Rambla.Handler
, theRambla.Handler
module will do the following things for your module:
- implement
@behaviour Finitomata.Pool.Actor
whereactor/2
will delegate tohandle_publish/2
expected to be implemented by this module, and overridableon_result/2
andon_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 ashandle_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
Callback resolution
Callbacks
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
@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