FullKafkaContainer¶
- class safir.testing.containers.FullKafkaContainer(image='confluentinc/cp-kafka:7.6.0', port=9093, ssl_port=29093, sasl_plaintext_port=29094, sasl_ssl_port=29095, **kwargs)¶
Bases:
DockerContainer
Kafka container.
Examples
from testcontainers.kafka import KafkaContainer with KafkaContainer() as kafka: connection = kafka.get_bootstrap_server()
- Parameters:
Methods Summary
create_file
(content, path)Create a file inside the container.
Get the bootstrap server for a no TLS, no SASL connection.
Get the configured SASL password for the Kafka listener.
Get the bootstrap server for a SASL PLAINTEXT connection.
Get the bootstrap server for a SASL TLS connection.
Get the configured SASL username for the Kafka listener.
get_secret_file_contents
(name)Get the contents of a file from
/etc/kafka/secrets
.Get the bootstrap server for a TLS connection.
reset
()Reset all Kafka topics.
start
([timeout])Start the container.
Methods Documentation
- create_file(content, path)¶
Create a file inside the container.
- get_sasl_plaintext_bootstrap_server()¶
Get the bootstrap server for a SASL PLAINTEXT connection.
- Return type:
- get_sasl_ssl_bootstrap_server()¶
Get the bootstrap server for a SASL TLS connection.
- Return type:
- get_secret_file_contents(name)¶
Get the contents of a file from
/etc/kafka/secrets
.Useful for getting TLS certs and keys for connecting with the SSL security protocol.
We can’t just mount a host volume over
/etc/kafka/secrets
because the OS user that owns that directory could be different than thatappuser
user that runs kafka in the container.- Parameters:
name (
str
) – Name of the secret to retrieve. This should normally be one ofca.crt
,client.crt
, orclient.key
.- Raises:
FileNotFoundError – Raised if the requested file could not be found in the
/etc/kafka/secrets
directory.- Return type: