# `Klife.TxnProducerPool`
[🔗](https://github.com/oliveigah/klife/blob/main/lib/klife/producer/txn_producer_pool.ex#L1)

Pool of transactional producers.

## Client configurations

* `:delivery_timeout_ms` (`t:non_neg_integer/0`) - The maximum amount of time the producer will retry to deliver a message before timing out and failing the send. The default value is `60000`.

* `:request_timeout_ms` (`t:non_neg_integer/0`) - The maximum amount of time the producer will wait for a broker response to a request before considering it as failed. The default value is `30000`.

* `:retry_backoff_ms` (`t:non_neg_integer/0`) - The amount of time that the producer waits before retrying a failed request to the broker. The default value is `1000`.

* `:compression_type` (`:none`, `:gzip` or `:snappy`) - The compression algorithm to be used for compressing messages before they are sent to the broker. The default value is `:none`.

* `:connection` (`t:atom/0`) - Name of the client connection used for every request of the pool's producers, transaction requests included. Defaults to the client's `default_connection`. See [Connections](guides/examples/client_configuration.md#connections).

* `:name` (`t:atom/0`) - Required. Pool name. Can be used as an option on the transactional api

* `:base_txn_id` (`t:String.t/0`) - Prefix used to define the `transactional_id` for the transactional producers. If not provided, a random string will be used. The default value is `""`.

* `:pool_size` (`t:non_neg_integer/0`) - Number of transactional producers in the pool The default value is `20`.

* `:txn_timeout_ms` (`t:non_neg_integer/0`) - The maximum amount of time, in milliseconds, that a transactional producer is allowed to remain open without either committing or aborting a transaction before it is considered expired The default value is `90000`.

## How to use?

When configuring `Klife.Client`, users can specify a list of transactional pools to be
initialized for sending records to the Kafka cluster.

Once configured, users can interact with these transactional producers through
the `Klife.Client` transaction API.

## Basic understanding

Since a single producer can only have a single open transaction at any given time,
Klife starts a pool of transactional producers that can be checked out by other
processes in order to execute transactions. The checkout and checkin are handled
automatically by the `Klife.Client` transaction API.

Each transactional producer is a standard `Klife.Producer` but with transactional
capabilities. The transactional behaviour can be tweaked using its specific configurations.

## Semantics

Transactions provide atomic writes across multiple topics and partitions, either all
records in a transaction are committed or none are. A more practical and guided discussion
about transaction semantics can be found on the `Klife.Client` transaction API.

# `in_txn?`

Checks if the current process is under a Kafka transaction.

## Example
    iex> false = Klife.TxnProducerPool.in_txn?(MyClient)

---

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