testcontainers-cpp 0.2.0
Native C++20 Testcontainers over the Docker Engine API
Loading...
Searching...
No Matches
testcontainers::modules::KafkaContainer Class Reference

A running single-node Kafka broker: address getters plus the owned container. More...

#include <testcontainers/modules/Kafka.hpp>

Public Member Functions

const std::string & bootstrap_servers () const noexcept
 The bootstrap.servers value for clients in THIS process (librdkafka, kcat, ...): "<host>:<mapped port>", e.g.
const std::string & internal_bootstrap_servers () const noexcept
 The bootstrap.servers value for OTHER CONTAINERS sharing the broker's user-defined network: "<first network alias>:9093" (or "<short container id>:9093" when no alias was configured — resolvable on user-defined networks, but not on the default bridge).
const std::string & host () const noexcept
 Host and mapped port of the client listener, for callers assembling their own config; bootstrap_servers() is host():port().
std::uint16_t port () const noexcept
const std::string & cluster_id () const noexcept
 The KRaft cluster id the broker was formatted with.
Containercontainer () noexcept
 The underlying container handle: exec the in-image CLI tools (bootstrap them at localhost:9093 — see kInternalPort), read logs, stop() early, keep() it past the test.
const Containercontainer () const noexcept

Friends

class KafkaImage

Detailed Description

A running single-node Kafka broker: address getters plus the owned container.

Move-only — it owns the core Container, whose destructor force-removes the broker (RAII teardown; container().keep() or reuse opt out, see Container). The address getters are resolved once, at start, and stay valid for the container's lifetime.

Member Function Documentation

◆ bootstrap_servers()

const std::string & testcontainers::modules::KafkaContainer::bootstrap_servers ( ) const
inlinenoexcept

The bootstrap.servers value for clients in THIS process (librdkafka, kcat, ...): "<host>:<mapped port>", e.g.

"localhost:32771". Bare host:port — no PLAINTEXT:// scheme (librdkafka rejects one).

◆ internal_bootstrap_servers()

const std::string & testcontainers::modules::KafkaContainer::internal_bootstrap_servers ( ) const
inlinenoexcept

The bootstrap.servers value for OTHER CONTAINERS sharing the broker's user-defined network: "<first network alias>:9093" (or "<short container id>:9093" when no alias was configured — resolvable on user-defined networks, but not on the default bridge).

Configure with_network + with_network_alias for a stable, readable value.

◆ host()

const std::string & testcontainers::modules::KafkaContainer::host ( ) const
inlinenoexcept

Host and mapped port of the client listener, for callers assembling their own config; bootstrap_servers() is host():port().

◆ port()

std::uint16_t testcontainers::modules::KafkaContainer::port ( ) const
inlinenoexcept

◆ cluster_id()

const std::string & testcontainers::modules::KafkaContainer::cluster_id ( ) const
inlinenoexcept

The KRaft cluster id the broker was formatted with.

◆ container() [1/2]

Container & testcontainers::modules::KafkaContainer::container ( )
inlinenoexcept

The underlying container handle: exec the in-image CLI tools (bootstrap them at localhost:9093 — see kInternalPort), read logs, stop() early, keep() it past the test.

◆ container() [2/2]

const Container & testcontainers::modules::KafkaContainer::container ( ) const
inlinenoexcept

◆ KafkaImage

friend class KafkaImage
friend