Carrot v1.1.0 Carrot.ConnectionManager View Source
AMQP Connection Manager.
This module is intended to be used in the context of a supervision tree. It provides a process that will manage a connection to an AMQP server, provides mechanism for configurable exponential backoff, and connection retry.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor
Opens a channel on the managed connection
Starts a connection manager process linked to the current process
Link to this section Types
Link to this type
connection_option()
View Source
connection_option() ::
{:username, String.t()}
| {:password, String.t()}
| {:virtual_host, String.t()}
| {:host, String.t()}
| {:port, pos_integer()}
| {:channel_max, pos_integer()}
| {:frame_max, pos_integer()}
| {:heartbeat, pos_integer()}
| {:connection_timeout, pos_integer()}
| {:backoff, backoff()}
| {:ssl_options, [:ssl.ssl_option()]}
| {:client_properties, [...]}
| {:socket_options, [:gen_tcp.option()]}
| {:url, String.t()}
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Link to this function
open_channel(server, timeout \\ 5000)
View Source
open_channel(GenServer.server(), pos_integer()) :: {:ok, AMQP.Channel.t()} | {:error, any()}
Opens a channel on the managed connection.
Examples
# Healthy connection
{:ok, pid} = Carrot.ConnectionManager.start_link([...])
{:ok, chan} = Carrot.ConnectionManager.open_channel(pid)
# Disconnected
{:error, :disconnected} = Carrot.ConnectionManager.open_channel(pid)
Link to this function
start_link(config, opts \\ [])
View Source
start_link(connection_options(), GenServer.options()) :: GenServer.on_start()
Starts a connection manager process linked to the current process.
This is intended to be called from a supervision tree.
Connection Options
: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 “/“);:host- The hostname of the broker (defaults to “localhost”);:port- The port the broker is listening on (defaults to5672);: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 to60000);: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 http://www.erlang.org/doc/man/inet.html#setopts-2 and http://www.erlang.org/doc/man/gen_tcp.html#connect-4 for descriptions of the available options.:url- The AMQP URI used to connect to the broker. If specified, it overrides all other connection options. See https://www.rabbitmq.com/uri-spec.html for more details on the RabbitMQ URI Specification
Enabling SSL
To enable SSL, supply the following in the ssl_options field:
cacertfile- Specifies the certificates of the root Certificate Authorities that we wish to implicitly trust;certfile- The client’s own certificate in PEM format;keyfile- The client’s private key in PEM format;