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, *, constant_host_ports=False, starting_host_port=50000, **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.
Start this container again.
Stop the container, but don't remove it.
wait_for_ready
([timeout])Wait until Kafka is ready to serve requests.
wait_for_ready_again
([timeout])Wait until Kafka is ready to serve requests.
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:
- start(timeout=30)¶
Start the container.
- Parameters:
timeout (
int
, default:30
) – How long to wait for the container to start before raising an error if Kafka still isn’t running.- Return type:
Self
- start_container_again()¶
Start this container again.
Can only be called after the container is stopped with stop_container.
- Return type:
- stop_container()¶
Stop the container, but don’t remove it.
This is useful in tests for stopping the container and starting it up again with the same ports mapped. The default stop method removes the container too, so if you call start again, it hass different ports mapped.
- Return type:
- wait_for_ready(timeout=30)¶
Wait until Kafka is ready to serve requests.