# `Kombu.Connection`
[🔗](https://github.com/hacktobeer/kombu/blob/v0.1.0/lib/kombu/connection.ex#L1)

Broker connection (`kombu.Connection`), managing transport resolution, URL parsing,
multi-URL failover (`round-robin` / `shuffle`), lazy connection & default channel creation,
and operation retry (`ensure_connection/2`, `ensure/4`, `autoretry/3`).

# `t`

```elixir
@type t() :: %Kombu.Connection{
  alternates: term(),
  connect_timeout: term(),
  credential_provider: term(),
  extra_opts: term(),
  failover_strategy: term(),
  heartbeat: term(),
  hostname: term(),
  initial_params: term(),
  insist: term(),
  login_method: term(),
  password: term(),
  port: term(),
  ssl: term(),
  state_pid: term(),
  transport: term(),
  transport_options: term(),
  uri_prefix: term(),
  userid: term(),
  virtual_host: term()
}
```

# `add_declared_entity`

```elixir
@spec add_declared_entity(t(), term()) :: :ok
```

Records `entity_key` in the connection's `declared_entities` set.

# `as_uri`

```elixir
@spec as_uri(t(), keyword()) :: String.t()
```

Formats the connection parameters as a URL string (`Connection.as_uri`).

# `autoretry`

```elixir
@spec autoretry(t(), function(), keyword()) :: function()
```

Wraps `fun` (which accepts `channel` as its last argument or via `:channel` option)
with automatic reconnection and channel revival, returning `{result, channel}`.

# `channel`

```elixir
@spec channel(t()) :: pid()
```

Creates and returns a new channel process for `conn`.

# `channel_pool`

# `channel_promise`

```elixir
@spec channel_promise(t()) :: (-&gt; pid())
```

Returns a 0-arity function that lazily returns the connection's `default_channel` (`Connection.channel_promise`).

# `check_url_transport!`

```elixir
@spec check_url_transport!(String.t()) :: String.t()
```

Validates a transport scheme extracted from a URL (forbidding `.` or `:`).

# `clear_declared_entities`

```elixir
@spec clear_declared_entities(t()) :: :ok
```

Clears all declared entities on `conn`.

# `clone`

```elixir
@spec clone(t(), keyword()) :: t()
```

Creates a clone of `conn` with optional parameter overrides.

# `close`

```elixir
@spec close(t()) :: t()
```

Alias for `release/1`.

# `collect`

```elixir
@spec collect(t(), number() | nil) :: t()
```

Cleans up connection resources and clears `declared_entities`.

# `completes_cycle?`

```elixir
@spec completes_cycle?(t(), non_neg_integer()) :: boolean()
```

Returns true if a failover cycle round is complete after `retries` (0-indexed).

# `connect`

```elixir
@spec connect(t()) :: map()
```

Establishes the connection immediately (`max_retries: 1`).
Returns the underlying transport connection map.

# `connected?`

```elixir
@spec connected?(t()) :: boolean()
```

Returns true if the connection is currently established and viable.

# `connection`

```elixir
@spec connection(t()) :: map() | nil
```

Returns the underlying transport connection map, connecting lazily if needed.

# `consumer`

# `declared_entities`

```elixir
@spec declared_entities(t()) :: MapSet.t()
```

Returns the set of entities declared on this connection session.

# `default_channel`

```elixir
@spec default_channel(t()) :: pid()
```

Returns the default channel for `conn`, creating it lazily if needed.

# `drain_events`

```elixir
@spec drain_events(t(), keyword()) :: :ok
```

Waits for a single event from the broker on `conn`'s default channel.

# `ensure`

```elixir
@spec ensure(t(), term(), function(), keyword()) :: function()
```

Wraps an operation `fun` on `obj` so that recoverable connection/channel errors
trigger reconnection, `revive`, and retry (`Connection.ensure`).

Returns a function accepting either `()` (0-arity) or `(args_list)` (1-arity)
that invokes `fun` with automatic retry and revival.

# `ensure_connection`

```elixir
@spec ensure_connection(t(), keyword()) :: t()
```

Ensures `conn` has an active connection to the broker, retrying according to `opts`
and rotating through alternate URLs if configured. Returns `conn`.

# `get_transport_cls`

```elixir
@spec get_transport_cls(String.t() | atom()) :: module()
```

Resolves a transport identifier (`"redis"`, `"rediss"`, `"memory"`, or module atom)
to its transport module.

# `has_declared_entity?`

```elixir
@spec has_declared_entity?(t(), term()) :: boolean()
```

Returns true if `entity_key` has been declared on this connection session.

# `heartbeat_check`

```elixir
@spec heartbeat_check(t(), keyword()) :: :ok
```

Checks heartbeats (no-op for transports that do not use heartbeats).

# `host`

```elixir
@spec host(t()) :: String.t()
```

Returns `"hostname:port"` for the connection.

# `info`

```elixir
@spec info(t()) :: map()
```

Returns connection parameters as a map (`Connection.info`).

# `is_connection?`

```elixir
@spec is_connection?(term()) :: boolean()
```

Returns true if `obj` is a `%Kombu.Connection{}`.

# `maybe_channel`

```elixir
@spec maybe_channel(t() | function() | Kombu.Channel.t()) :: Kombu.Channel.t()
```

Resolves a connection, channel promise, or channel into a concrete channel.

# `maybe_close_channel`

```elixir
@spec maybe_close_channel(t(), pid() | nil) :: :ok
```

Closes `channel`, ignoring any connection or channel errors.

# `maybe_switch_next`

```elixir
@spec maybe_switch_next(t()) :: t()
```

Switches to the next alternate URL according to the configured failover strategy.

# `new`

```elixir
@spec new(String.t() | [String.t()] | keyword(), keyword()) :: t()
```

Creates a new `%Kombu.Connection{}` from a URL string, list of URLs, or keyword options.

# `pool`

# `producer`

# `producer_pool`

# `recoverable_channel_errors`

Returns the list of recoverable channel error modules for `conn`.

# `recoverable_connection_errors`

Returns the list of recoverable connection error modules for `conn`.

# `release`

```elixir
@spec release(t()) :: t()
```

Closes the connection and its default channel, clearing declared entities.

# `reset_declared_entities`

```elixir
@spec reset_declared_entities(t()) :: :ok
```

Alias for `clear_declared_entities/1`.

# `revive`

```elixir
@spec revive(t(), pid() | nil) :: t()
```

Revives the connection after re-establishment, closing old default channel if replaced.

# `simple_buffer`

# `simple_queue`

# `supports_exchange_type?`

```elixir
@spec supports_exchange_type?(t(), String.t()) :: boolean()
```

Returns true if the connection's transport supports `exchange_type`.

# `switch`

```elixir
@spec switch(t(), String.t()) :: t()
```

Switches connection parameters to `conn_str` (URL or hostname) without reconnecting.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
