hare v0.2.2 Hare.Core.Conn.State.Bridge

This module defines the Conn.State.Bridge struct that keeps the state and configuration of the AMQP connection, and the main functions for working with it.

Bridge fields

Adapter fields:

  • adapter - the adapter to the underlying AMQP library
  • config - the configuration to be given to the adapter when opening connection

Retrying failed connection fields:

  • backoff - a list of time intervals (in ms) to wait to retry a failed connection
  • next_intervals - the list of remaining backoff intervals for the current retrying process

Information regarding the current active connection:

  • given - the term given by the AMQP adapter representing a connection
  • ref - the monitoring reference for the connection
  • status - the current connection status (:not_connected | :connected | :reconnecting)

Backoff and failed connections

When the connect/1 function is called and the AMQP adapter fails to establish connection the status is set to :reconnecting and it {:retry, backoff_interval, reason, new_state}. When connect/1 is called again and it fails again the same response is given with the next backoff interval. When all but one backoff intervals have been returned, the last one is returned forever.

Summary

Functions

Establishes connection through the AMQP adapter

Disconnects the current connection

Returns the current AMQP adapter connection term

Creates a new Bridge struct

Opens a new channel on the active connection

Types

adapter()
adapter() :: Hare.Adapter.t
adapter_config()
adapter_config() :: term
backoff()
backoff() :: [interval]
config()
config() :: [config_option]
config_option()
config_option ::
  {:adapter, adapter} |
  {:backoff, backoff} |
  {:config, adapter_config}
given()
given() :: Hare.Adapter.conn
interval()
interval() :: non_neg_integer
status()
status() :: :not_connected | :connected | :reconnecting
t()
t() :: %Hare.Core.Conn.State.Bridge{adapter: adapter, backoff: backoff, config: adapter_config, given: given | nil, next_intervals: backoff, ref: reference | nil, status: status}

Functions

connect(bridge)
connect(t) ::
  {:ok, t} |
  {:retry, interval, reason :: term, t}

Establishes connection through the AMQP adapter.

On success it returns {:ok, bridge}. On failure it returns {:retry, interval, reason, bridge} and expects the caller to wait that interval before calling connect/1 again.

disconnect(bridge)
disconnect(t) :: t

Disconnects the current connection.

If connected it disconnects, otherwise it does nothing.

given_conn(bridge)
given_conn(t) :: Hare.Adapter.conn

Returns the current AMQP adapter connection term.

new(config)
new(config) :: t

Creates a new Bridge struct.

It expect the given config to contain the following fields:

  • :adapter - the AMQP adapter to use
  • :backoff - the list of backoff intervals
  • :config - the AMQP adapter config to use when establishing connection
open_channel(bridge)
open_channel(t) ::
  {:ok, Hare.Adapter.chan} |
  {:error, reason :: term} |
  :not_connected

Opens a new channel on the active connection.

When the status is :connected, it returns the adapter’s open_channel/1 result, otherwise it returns :not_connected.