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

Functions to operate on Queues.

# `bind`

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

Binds a Queue to an Exchange.

## Options

  * `:routing_key` - The routing key used to bind the queue to the exchange
    (default `""`)

  * `:nowait` - If `true`, the binding is not synchronous (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 `[]`)

# `consumer_count`

```elixir
@spec consumer_count(AMQP.Channel.t(), AMQP.Basic.queue()) :: integer() | no_return()
```

Returns a number of active consumers on the queue.

# `declare`

```elixir
@spec declare(AMQP.Channel.t(), AMQP.Basic.queue(), keyword()) ::
  {:ok,
   %{
     queue: AMQP.Basic.queue(),
     message_count: integer(),
     consumer_count: integer()
   }}
  | :ok
  | AMQP.Basic.error()
```

Declares a queue. The optional `queue` parameter is used to set the name.
If set to an empty string (default), the server will assign a name.

Besides the queue name, the following options can be used:

## Options

  * `:durable` - If set, keeps the Queue between restarts of the broker
    (default `false`)

  * `:auto_delete` - If set, deletes the Queue once all subscribers
    disconnect (default to `false`)

  * `:exclusive` - If set, only one subscriber can consume from the Queue
    (default `false`)

  * `:passive` - If set, raises an error unless the queue already exists
    (default `false`)

  * `: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 `[]`)

# `delete`

```elixir
@spec delete(AMQP.Channel.t(), AMQP.Basic.queue(), keyword()) ::
  {:ok, map()} | :ok | AMQP.Basic.error()
```

Deletes a Queue by name.

## Options

  * `:if_unused` - If set, the server will only delete the queue if it has no
    consumers. If the queue has consumers, it's not deleted and an error is
    returned

  * `:if_empty` - If set, the server will only delete the queue if it has no
    messages

  * `:nowait` - If set, the delete operation is asynchronous

# `empty?`

```elixir
@spec empty?(AMQP.Channel.t(), AMQP.Basic.queue()) :: boolean() | no_return()
```

Returns true if queue is empty (has no messages ready), false otherwise.

# `message_count`

```elixir
@spec message_count(AMQP.Channel.t(), AMQP.Basic.queue()) :: integer() | no_return()
```

Returns the number of messages that are ready for delivery (e.g. not pending
acknowledgements) in the queue.

# `purge`

```elixir
@spec purge(AMQP.Channel.t(), AMQP.Basic.queue(), keyword()) ::
  {:ok, map()} | :ok | AMQP.Basic.error()
```

Discards all messages in the Queue.

Set `:nowait` (or its alias `:no_wait`) to `true` to skip waiting for the
broker's reply and return `:ok` instead of the message count.

# `status`

```elixir
@spec status(AMQP.Channel.t(), AMQP.Basic.queue()) ::
  {:ok, map()} | AMQP.Basic.error()
```

Returns the message count and consumer count for the given queue.
Uses `declare/3` with the `:passive` option set.

# `subscribe`

```elixir
@spec subscribe(
  AMQP.Channel.t(),
  AMQP.Basic.queue(),
  (String.t(), map() -&gt; any()),
  keyword()
) ::
  {:ok, String.t()} | AMQP.Basic.error()
```

Convenience to consume messages from a Queue.

The handler function must have arity 2 and will receive as arguments a binary
with the message payload and a Map with the message properties.

The consumed message will be acknowledged after executing the handler function.

If an exception is raised by the handler function, the message is rejected.

This convenience function will spawn a process and register it using
`AMQP.Basic.consume/4`.

# `unbind`

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

Unbinds a Queue from an Exchange.

## Options

  * `:routing_key` - The routing queue for removing the binding (default `""`)

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

# `unsubscribe`

```elixir
@spec unsubscribe(AMQP.Channel.t(), AMQP.Basic.consumer_tag()) ::
  {:ok, String.t()} | AMQP.Basic.error()
```

Stops the consumer identified by `consumer_tag` from consuming.

Internally just calls `AMQP.Basic.cancel/2`.

---

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