RMQ v0.1.0-beta.1 RMQ.Connection behaviour View Source
A GenServer
which provides a robust connection to RabbitMQ broker.
Can be used as following:
defmodule MyApp.RabbitConnection do
use RMQ.Connection,
otp_app: :my_app,
uri: "amqp://localhost",
connection_name: to_string(__MODULE__)
end
Can be configured via the application environment:
config :my_app, MyApp.RabbitConnection,
uri: "amqp://localhost",
connection_name: "MyApp.RabbitConnection"
Supports dynamic configuration via config/0
callback:
defmodule MyApp.RabbitConnection do
use RMQ.Connection, otp_app: :my_app
def config do
[
uri: System.get_env("RABBIT_URL", "amqp://localhost"),
connection_name: to_string(__MODULE__)
]
end
end
Configuration
:otp_app
- the only required value. It should point to an OTP application that has the connection configuration.:uri
- AMQP URI. Defaults to"amqp://localhost"
;:connection_name
- RabbitMQ connection name. Defaults to:undefined
;:reconnect_interval
- reconnect interval. Defaults to5000
;- options for
AMQP.Connection.open/3
.
Link to this section Summary
Link to this section Callbacks
Callback for dynamic configuration.
Can be used in case the connection configuration needs to be set dynamically, for example by reading a system environment variable.
Link to this callback
get_connection()
View Sourceget_connection() :: {:ok, AMQP.Connection.t()} | {:error, :not_connected}
Gets the connection.
Link to this callback
start_link(options)
View Sourcestart_link(options :: [GenServer.option()]) :: GenServer.on_start()
Starts a GenServer
process linked to the current process.