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

Message Producer (`kombu.Producer`).

Handles serialization (`Kombu.Serialization`), compression (`Kombu.Compression`),
automatic exchange/entity declaration (`maybe_declare`), connection retry (`ensure`),
and batched Redis publishing (`Producer.batch/3`).

# `t`

```elixir
@type t() :: %Kombu.Producer{
  auto_declare: term(),
  channel: term(),
  compression: term(),
  connection: term(),
  exchange: term(),
  on_return: term(),
  routing_key: term(),
  serializer: term()
}
```

# `batch`

```elixir
@spec batch(t(), pos_integer() | keyword(), (map() -&gt; result) | (-&gt; result)) :: result
when result: var
```

Executes `fun` within a batched publish session (`with producer.batch(max_size=...)`).

Supports nested `Producer.batch` blocks on the same process. When the outermost
`batch` block exits normally, any buffered messages are flushed in a single pipeline.
If an exception is raised, buffered messages are discarded.

# `channel`

```elixir
@spec channel(t()) :: Kombu.Channel.t()
```

Resolves and returns the concrete channel for `producer`.

# `close`

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

# `declare`

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

Declares the producer's default exchange if it has a non-empty name (`Producer.declare`).

# `flush_active_batch!`

```elixir
@spec flush_active_batch!() :: :ok
```

Flushes any messages currently buffered in the active `Producer.batch` context.

# `maybe_declare`

```elixir
@spec maybe_declare(t(), term(), keyword()) :: boolean()
```

Declares `entity` unless already declared during this connection session (`Producer.maybe_declare`).

# `new`

```elixir
@spec new(Kombu.Connection.t() | Kombu.Channel.t() | function() | nil, keyword()) ::
  t()
```

Creates a new `%Kombu.Producer{}`.

# `prepare`

```elixir
@spec prepare(t(), term(), keyword()) :: {binary(), String.t(), String.t(), map()}
```

Serializes and optionally compresses `body` for publishing (`Producer._prepare`).

Returns `{prepared_body, content_type, content_encoding, updated_headers}`.

# `publish`

```elixir
@spec publish(t(), term(), keyword()) :: :ok
```

Publishes a message to the broker (`Producer.publish`).

# `release`

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

Releases the producer (`Producer.release` / `Producer.close`).

# `revive`

```elixir
@spec revive(t(), Kombu.Connection.t() | Kombu.Channel.t() | function()) :: t()
```

Revives the producer with a new channel or connection after connection loss (`Producer.revive`).

# `supports_batch_publish?`

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

Returns true if the active transport supports batched publishing (`Producer.supports_batch_publish`).

---

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