Freddy.Connection (freddy v0.17.2)
Stable AMQP connection.
Link to this section Summary
Types
Freddy adapter. Can be any module, but also can be passed as an alias :amqp
or :sandox
Keyword list of AMQP connection params.
Functions
Closes an AMQP connection. This will cause process to reconnect.
Returns underlying connection PID
Opens a new AMQP channel
Start a new AMQP connection.
Stops the connection process
Link to this section Types
adapter()
Specs
adapter() :: :amqp | :sandbox | module()
Freddy adapter. Can be any module, but also can be passed as an alias :amqp
or :sandox
connection()
Specs
connection() :: GenServer.server()
connection_params()
Specs
connection_params() :: [ adapter: atom(), backoff: Freddy.Utils.Backoff.spec(), host: String.t(), port: integer(), username: String.t(), password: String.t(), virtual_host: String.t(), channel_max: non_neg_integer(), frame_max: non_neg_integer(), heartbeat: non_neg_integer(), connection_timeout: timeout(), client_properties: [{String.t(), atom(), String.t()}], ssl_options: term(), socket_options: [any()], auth_mechanisms: [function()] ]
Keyword list of AMQP connection params.
Options
:adapter
- Freddy adapter. Can be any module, but also can be passed as an alias:amqp
or:sandox
:backoff
- Backoff can be specified either as a 1-arity function that accepts attempt number (starting from1
) , or as a tuple{module, function, arguments}
(in this case attempt number will appended to the arguments) or as a backoff config.:host
- The hostname of the broker (defaults to "localhost"):port
- The port the broker is listening on (defaults to5672
):username
- The name of a user registered with the broker (defaults to "guest"):password
- The password of user (defaults to "guest"):virtual_host
- The name of a virtual host in the broker (defaults to "/"):channel_max
- The channel_max handshake parameter (defaults to0
):frame_max
- The frame_max handshake parameter (defaults to0
):heartbeat
- The hearbeat interval in seconds (defaults to10
):connection_timeout
- The connection timeout in milliseconds (defaults to5000
):ssl_options
- Enable SSL by setting the location to cert files (defaults tonone
):client_properties
- A list of extra client properties to be sent to the server, defaults to[]
:socket_options
- Extra socket options. These are appended to the default options. See:inet.setopts/2
and:gen_tcp.connect/4
for descriptions of the available options.
connection_spec()
Specs
connection_spec() :: connection_params() | connection_uri()
connection_uri()
Specs
connection_uri() :: String.t()
Link to this section Functions
close(connection, timeout \\ 5000)
Specs
close(connection(), timeout()) :: :ok | {:error, reason :: term()}
Closes an AMQP connection. This will cause process to reconnect.
get_connection(connection)
Specs
get_connection(connection()) :: {:ok, Freddy.Adapter.connection()} | {:error, :closed}
Returns underlying connection PID
open_channel(connection, timeout \\ 5000)
Specs
open_channel(connection(), timeout()) :: {:ok, Freddy.Core.Channel.t()} | {:error, reason :: term()}
Opens a new AMQP channel
start_link(connection_opts \\ [], gen_server_opts \\ [])
Specs
start_link(connection_spec() | [connection_spec(), ...], GenServer.options()) :: GenServer.on_start()
Start a new AMQP connection.
connection_opts
can be supplied either as keyword list - in this case
connection will be established to one RabbitMQ server - or as a list of
keyword list - in this case Freddy.Connection
will first attempt to
establish connection to the host specified by the first element of the list,
then to the second, if the first one has failed, and so on.
Options
:adapter
- Freddy adapter. Can be any module, but also can be passed as an alias:amqp
or:sandox
:backoff
- Backoff can be specified either as a 1-arity function that accepts attempt number (starting from1
) , or as a tuple{module, function, arguments}
(in this case attempt number will appended to the arguments) or as a backoff config.:host
- The hostname of the broker (defaults to "localhost"):port
- The port the broker is listening on (defaults to5672
):username
- The name of a user registered with the broker (defaults to "guest"):password
- The password of user (defaults to "guest"):virtual_host
- The name of a virtual host in the broker (defaults to "/"):channel_max
- The channel_max handshake parameter (defaults to0
):frame_max
- The frame_max handshake parameter (defaults to0
):heartbeat
- The hearbeat interval in seconds (defaults to10
):connection_timeout
- The connection timeout in milliseconds (defaults to5000
):ssl_options
- Enable SSL by setting the location to cert files (defaults tonone
):client_properties
- A list of extra client properties to be sent to the server, defaults to[]
:socket_options
- Extra socket options. These are appended to the default options. See:inet.setopts/2
and:gen_tcp.connect/4
for descriptions of the available options.
Backoff configuration
Backoff config specifies how intervals should be calculated between reconnection attempts.
Available options
:type
- should be:constant
,:normal
or:jitter
. When type is set to:constant
, interval between all reconnection attempts is the same, defined by option:start
. When type is set to:normal
, intervals between reconnection attempts are incremented exponentially. When type is set to:jitter
, intervals are also incremented exponentially, but with randomness or jitter (see:backoff.rand_increment/2
). Defaults to:jitter
.:start
- an initial backoff interval in milliseconds. Defaults to1000
.:max
- specifies maximum backoff interval in milliseconds. Defaults to10000
.
stop(connection)
Stops the connection process