# `AMQP.Exchange`
[🔗](https://github.com/pma/amqp/blob/v4.3.0/lib/amqp/exchange.ex#L1)

Functions to operate on Exchanges.

# `bind`

```elixir
@spec bind(
  AMQP.Channel.t(),
  destination :: String.t(),
  source :: String.t(),
  keyword()
) ::
  :ok | AMQP.Basic.error()
```

Binds an Exchange to another Exchange using the exchange.bind AMQP method (a
RabbitMQ-specific extension).

## Options

  * `:routing_key` - the routing key to use for the binding (default `""`)

  * `:nowait` - If set, the bind operation is asynchronous (default `false`)

  * `:arguments` - A list of arguments to pass when binding (of type
    `t:AMQP.arguments/0`). See the [README](readme.html) for more information
    (default to `[]`)

# `declare`

```elixir
@spec declare(AMQP.Channel.t(), AMQP.Basic.exchange(), type :: atom(), keyword()) ::
  :ok | AMQP.Basic.error()
```

Declares an Exchange. The default Exchange type is `direct`.

AMQP 0-9-1 brokers provide four pre-declared exchanges:

  * `:direct` exchange: (empty string) or `amq.direct`

  * `:fanout` exchange: `amq.fanout`

  * `:topic` exchange: `amq.topic`

  * `:headers` exchange: `amq.match` (and `amq.headers` in RabbitMQ)

Besides the exchange name and type, the following options can be used:

## Options

  * `:durable` - If set, keeps the Exchange between restarts of the broker

  * `:auto_delete` - If set, deletes the Exchange once all queues unbind from
    it

  * `:passive` - If set, returns an error if the Exchange does not already
    exist

  * `:internal` - If set, the exchange may not be used directly by
    publishers, but only when bound to other exchanges. Internal exchanges are
    used to construct wiring that is not visible to applications

  * `:nowait` - If set, the declare operation is asynchronous (default `false`)

  * `:arguments` - A list of arguments to pass when declaring (of type
    `t:AMQP.arguments/0`).  See the [README](readme.html) for more information
    (default to `[]`)

# `delete`

```elixir
@spec delete(AMQP.Channel.t(), AMQP.Basic.exchange(), keyword()) ::
  :ok | AMQP.Basic.error()
```

Deletes an Exchange by name. When an Exchange is deleted all bindings to it are
also deleted.

## Options

  * `:if_unused` - If set, the server will only delete the exchange if it has
    no queue bindings

  * `:nowait` - If set, the delete operation is asynchronous (default
    `false`)

# `direct`

```elixir
@spec direct(AMQP.Channel.t(), AMQP.Basic.exchange(), keyword()) ::
  :ok | AMQP.Basic.error()
```

Convenience function to declare an Exchange of type `direct`.

## Options

This function takes the same options as `declare/4`.

# `fanout`

```elixir
@spec fanout(AMQP.Channel.t(), AMQP.Basic.exchange(), keyword()) ::
  :ok | AMQP.Basic.error()
```

Convenience function to declare an Exchange of type `fanout`.

## Options

This function takes the same options as `declare/4`.

# `topic`

```elixir
@spec topic(AMQP.Channel.t(), AMQP.Basic.exchange(), keyword()) ::
  :ok | AMQP.Basic.error()
```

Convenience function to declare an Exchange of type `topic`.

## Options

This function takes the same options as `declare/4`.

# `unbind`

```elixir
@spec unbind(
  AMQP.Channel.t(),
  destination :: String.t(),
  source :: String.t(),
  keyword()
) ::
  :ok | AMQP.Basic.error()
```

Unbinds an Exchange from another Exchange or a Queue using the
exchange.unbind AMQP method (a RabbitMQ-specific extension).

## Options

  * `:routing_key` - the routing key to use for the binding (default `""`)

  * `:nowait` - If set, the declare operation is asynchronous (default `false`)

  * `:arguments` - A list of arguments to pass when declaring (of type
    `t:AMQP.arguments/0`). See the README for more information (defaults `[]`)

---

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