amqp v1.1.1 AMQP.Connection View Source

Functions to operate on Connections.

Link to this section Summary


Closes an open Connection

Opens an new Connection to an AMQP broker

Link to this section Types

Link to this type t() View Source
t() :: %AMQP.Connection{pid: pid()}

Link to this section Functions

Link to this function close(conn) View Source
close(t()) :: :ok | {:error, any()}

Closes an open Connection.

Link to this function open(options \\ []) View Source
open(keyword() | String.t()) ::
  {:ok, t()} | {:error, atom()} | {:error, any()}

Opens an new Connection to an AMQP broker.

The connections created by this module are supervised under amqp_client’s supervision tree. Please note that connections do not get restarted automatically by the supervision tree in case of a failure. If you need robust connections and channels, use monitors on the returned connection PID.

The connection parameters can be passed as a keyword list or as a AMQP URI.

When using a keyword list, the following options can be used:


  • :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 to 5672);
  • :channel_max - The channel_max handshake parameter (defaults to 0);
  • :frame_max - The frame_max handshake parameter (defaults to 0);
  • :heartbeat - The hearbeat interval in seconds (defaults to 10);
  • :connection_timeout - The connection timeout in milliseconds (defaults to 60000);
  • :ssl_options - Enable SSL by setting the location to cert files (defaults to :none);
  • :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 and for descriptions of the available options.

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;

Example port: 5671,
                     ssl_options: [cacertfile: '/path/to/testca/cacert.pem',
                                   certfile: '/path/to/client/cert.pem',
                                   keyfile: '/path/to/client/key.pem',
                                   # only necessary with intermediate CAs
                                   # depth: 2,
                                   verify: :verify_peer,
                                   fail_if_no_peer_cert: true]


iex> host: "localhost", port: 5672, virtual_host: "/", username: "guest", password: "guest"
{:ok, %AMQP.Connection{}}

iex> "amqp://guest:guest@localhost"
{:ok, %AMQP.Connection{}}