# `Testcontainers.KafkaContainer`
[🔗](https://github.com/testcontainers/testcontainers-elixir/blob/main/lib/container/kafka_container.ex#L1)

Provides functionality for creating and managing Kafka container configurations.

This implementation uses the official `apache/kafka` Docker image which runs in KRaft mode
by default (no Zookeeper required). This makes Kafka deployment significantly simpler.

## Example

    config = KafkaContainer.new()
    {:ok, container} = Testcontainers.start_container(config)

    # Get the bootstrap server address
    bootstrap_servers = KafkaContainer.bootstrap_servers(container)

## With automatic topic creation

    config =
      KafkaContainer.new()
      |> KafkaContainer.with_topics(["my-topic", "other-topic"])

    {:ok, container} = Testcontainers.start_container(config)

## Note on Port Binding

This implementation uses a randomly selected fixed host port (between 29000-29999) for
the Kafka listener. This is necessary because the apache/kafka image requires knowing
the advertised listener address at startup time, before the container's dynamic port
mapping is known.

If you need to use a specific port, you can set it with `with_kafka_port/2`.

# `t`

```elixir
@type t() :: %Testcontainers.KafkaContainer{
  cluster_id: term(),
  controller_port: term(),
  image: term(),
  internal_kafka_port: term(),
  kafka_port: term(),
  node_id: term(),
  reuse: term(),
  topics: term(),
  wait_timeout: term()
}
```

# `bootstrap_servers`

Returns the bootstrap servers string for connecting to the Kafka container.

# `new`

Creates a new `KafkaContainer` struct with default configurations.

A random port between 29000-29999 is selected for the Kafka listener.

# `port`

Returns the port on the host machine where the Kafka container is listening.

# `with_cluster_id`

Overrides the default cluster id used for the Kafka container.

# `with_controller_port`

Overrides the default controller port used for the Kafka container.

# `with_image`

Overrides the default image used for the Kafka container.

# `with_kafka_port`

Overrides the host port used for the Kafka container.

This port will be used on the host machine and also as the advertised listener port.

# `with_node_id`

Overrides the default node id used for the Kafka container.

# `with_reuse`

Set the reuse flag to reuse the container if it is already running.

# `with_topics`

Sets the topics to be created automatically when the container starts.

## Example

    config =
      KafkaContainer.new()
      |> KafkaContainer.with_topics(["my-topic", "other-topic"])

# `with_wait_timeout`

Overrides the default wait timeout used for the Kafka container.

---

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