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

An Exchange declaration (`kombu.entity.Exchange`).

# `t`

```elixir
@type t() :: %Kombu.Exchange{
  arguments: map() | nil,
  auto_delete: boolean(),
  channel: Kombu.Channel.t() | nil,
  delivery_mode: 1 | 2 | nil,
  durable: boolean(),
  extra: map(),
  name: String.t(),
  no_declare: boolean(),
  passive: boolean(),
  routing_key: String.t() | nil,
  type: String.t()
}
```

# `as_dict`

```elixir
@spec as_dict(t(), keyword()) :: map()
```

Converts the exchange into a dictionary/map representation (`as_dict`).

# `assert_bound!`

```elixir
@spec assert_bound!(t(), Kombu.Channel.t() | nil) :: Kombu.Channel.t()
```

Raises `Kombu.NotBoundError` if neither `exchange.channel` nor `channel` is bound.

# `bind`

```elixir
@spec bind(t(), Kombu.Channel.t() | nil) :: t()
```

Returns a copy of `exchange` bound to `channel`.

# `bind_to`

```elixir
@spec bind_to(t(), t() | String.t(), keyword()) :: term()
```

Binds this exchange to `source` exchange (`exchange.bind_to`).

# `binding`

```elixir
@spec binding(t(), keyword()) :: Kombu.Binding.t()
```

Creates a `%Kombu.Binding{}` for this exchange.

# `bound?`

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

Returns `true` if the exchange is bound to a channel.

# `can_cache_declaration?`

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

Returns `true` if declaration of this exchange can be cached (`not auto_delete`).

# `can_declare?`

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

Returns `true` if this exchange should be declared on the broker.
Exchanges with `no_declare: true`, empty name `""`, or starting with `"amq."` are not declared.

# `declare`

```elixir
@spec declare(t(), keyword()) :: term()
```

Declares the exchange on the broker channel if `can_declare?/1` is true.

# `delete`

```elixir
@spec delete(t(), keyword()) :: term()
```

Deletes the exchange from the broker.

# `delivery_modes`

```elixir
@spec delivery_modes() :: map()
```

Returns the delivery modes mapping.

# `equal?`

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

Compares two `%Kombu.Exchange{}` structs for value equality (ignoring channel binding).

# `equivalent?`

```elixir
@spec equivalent?(t() | map(), t() | map()) :: boolean()
```

Checks if two exchange declarations are equivalent (`type`, `durable`, `auto_delete`, `arguments`),
matching `kombu.transport.virtual.exchange.ExchangeType.is_equivalent`.

# `maybe_bind`

```elixir
@spec maybe_bind(t(), Kombu.Channel.t() | nil) :: t()
```

Binds the exchange to `channel` if not already bound and `channel` is non-nil.

# `maybe_delivery_mode`

```elixir
@spec maybe_delivery_mode(term(), map(), 1 | 2) :: 1 | 2
```

Normalizes a delivery mode (`"transient"`, `"persistent"`, `:transient`, `:persistent`, `1`, `2`)
into its integer representation (`1` or `2`). Defaults to `2` (persistent) when `nil`.

# `message`

```elixir
@spec message(t(), term(), keyword()) :: map()
```

Creates a prepared message map to be published to this exchange (`Exchange.Message`).

# `new`

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

Constructs a `%Kombu.Exchange{}` struct, or returns an existing `%Kombu.Exchange{}`
(optionally binding it to `opts[:channel]`).

# `persistent_delivery_mode`

```elixir
@spec persistent_delivery_mode() :: 2
```

Returns the persistent delivery mode constant (`2`).

# `publish`

```elixir
@spec publish(t(), map(), String.t() | keyword() | nil, keyword()) :: term()
```

Publishes a prepared message to the exchange.
Accepts either `publish(exchange, message, opts)` or `publish(exchange, message, routing_key, opts \ [])`.

# `revive`

```elixir
@spec revive(t(), term()) :: t()
```

Revives the exchange with a new channel (`Exchange.revive`).

# `transient_delivery_mode`

```elixir
@spec transient_delivery_mode() :: 1
```

Returns the transient delivery mode constant (`1`).

# `unbind_from`

```elixir
@spec unbind_from(t(), t() | String.t(), keyword()) :: term()
```

Unbinds this exchange from `source` exchange (`exchange.unbind_from`).

---

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