Package io.strimzi.test.container
Class StrimziKafkaCluster.StrimziKafkaClusterBuilder
java.lang.Object
io.strimzi.test.container.StrimziKafkaCluster.StrimziKafkaClusterBuilder
- Enclosing class:
- StrimziKafkaCluster
Builder class for
StrimziKafkaCluster.
Use this builder to create instances of StrimziKafkaCluster with customized configurations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds and returns aStrimziKafkaClusterinstance based on the provided configurations.withAdditionalKafkaConfiguration(Map<String, String> additionalKafkaConfiguration) Adds additional Kafka configuration parameters.withAuthenticationType(AuthenticationType authType) Sets the authentication type for all nodes in the cluster.withBootstrapServers(Function<StrimziKafkaContainer, String> provider) Assigns a provider function for overriding the bootstrap servers string for all broker nodes.withContainerCustomizer(Consumer<StrimziKafkaContainer> customizer) Assigns a customizer function to modify each Kafka container after its creation.Configures the cluster to use dedicated controller and broker nodes instead of combined-role nodes.Specifies a custom Docker image to be used for the Kafka brokers in the cluster.withInternalTopicReplicationFactor(int internalTopicReplicationFactor) Sets the internal topic replication factor for Kafka brokers.withKafkaVersion(String kafkaVersion) Specifies the Kafka version to be used for the brokers in the cluster.Fluent method to enable log collection with a default log file path.withLogCollection(String logFilePath) Fluent method to enable log collection for all containers in the cluster with a custom log file path.withNumberOfBrokers(int brokersNum) Sets the number of Kafka brokers in the cluster.withNumberOfControllers(int controllersNum) Sets the number of dedicated controller nodes when using combined roles.withOAuthConfig(String realm, String clientId, String clientSecret, String oauthUri, String usernameClaim) Configures OAuth settings for all nodes in the cluster.withPort(int fixedPort) Sets a fixed exposed port for all broker nodes in the cluster.withProxyContainer(org.testcontainers.toxiproxy.ToxiproxyContainer proxyContainer) Sets aToxiproxyContainerto simulate network conditions such as latency or disconnection.withSaslPassword(String saslPassword) Sets the SASL password for OAuth over PLAIN authentication.withSaslUsername(String saslUsername) Sets the SASL username for OAuth over PLAIN authentication.Enables a shared Docker network for the Kafka cluster.
-
Constructor Details
-
StrimziKafkaClusterBuilder
public StrimziKafkaClusterBuilder()
-
-
Method Details
-
withNumberOfBrokers
Sets the number of Kafka brokers in the cluster.- Parameters:
brokersNum- the number of Kafka brokers- Returns:
- the current instance of
StrimziConnectClusterBuilderfor method chaining
-
withInternalTopicReplicationFactor
public StrimziKafkaCluster.StrimziKafkaClusterBuilder withInternalTopicReplicationFactor(int internalTopicReplicationFactor) Sets the internal topic replication factor for Kafka brokers. If not provided, it defaults to the number of brokers.- Parameters:
internalTopicReplicationFactor- the replication factor for internal topics- Returns:
- the current instance of
StrimziConnectClusterBuilderfor method chaining
-
withAdditionalKafkaConfiguration
public StrimziKafkaCluster.StrimziKafkaClusterBuilder withAdditionalKafkaConfiguration(Map<String, String> additionalKafkaConfiguration) Adds additional Kafka configuration parameters. These configurations are applied to all brokers in the cluster.- Parameters:
additionalKafkaConfiguration- a map of additional Kafka configuration options- Returns:
- the current instance of
StrimziConnectClusterBuilderfor method chaining
-
withProxyContainer
public StrimziKafkaCluster.StrimziKafkaClusterBuilder withProxyContainer(org.testcontainers.toxiproxy.ToxiproxyContainer proxyContainer) Sets aToxiproxyContainerto simulate network conditions such as latency or disconnection.- Parameters:
proxyContainer- the proxy container for simulating network conditions- Returns:
- the current instance of
StrimziConnectClusterBuilderfor method chaining
-
withKafkaVersion
Specifies the Kafka version to be used for the brokers in the cluster. If no version is provided, the latest Kafka version available fromKafkaVersionServicewill be used.- Parameters:
kafkaVersion- the desired Kafka version for the cluster- Returns:
- the current instance of
StrimziKafkaClusterBuilderfor method chaining
-
withImage
Specifies a custom Docker image to be used for the Kafka brokers in the cluster. This allows using custom Kafka images instead of the default Strimzi test container images.When this is set, the image specified here takes precedence over the version-based image selection.
- Parameters:
kafkaImage- the full Docker image name- Returns:
- the current instance of
StrimziKafkaClusterBuilderfor method chaining - Throws:
IllegalArgumentException- if the image name is null or empty
-
withDedicatedRoles
Configures the cluster to use dedicated controller and broker nodes instead of combined-role nodes. When enabled, you must also specify the number of controllers usingwithNumberOfControllers(int).- Returns:
- the current instance of
StrimziKafkaClusterBuilderfor method chaining
-
withNumberOfControllers
Sets the number of dedicated controller nodes when using combined roles. This method should be used in conjunction withwithDedicatedRoles().- Parameters:
controllersNum- the number of dedicated controller nodes- Returns:
- the current instance of
StrimziKafkaClusterBuilderfor method chaining
-
withLogCollection
Fluent method to enable log collection with a default log file path. The actual filename is determined at runtime when logs are collected.- Returns:
- StrimziKafkaContainer instance for method chaining
-
withLogCollection
Fluent method to enable log collection for all containers in the cluster with a custom log file path. If the path ends with "/", role-based filenames are automatically appended at runtime for each container: Controller-only: "kafka-controller-{nodeId}.log" Broker-only: "kafka-broker-{nodeId}.log" Combined: "kafka-container-{nodeId}.log" otherwise, the path doesn't end with "/", it's used as the exact filename base for all containers- Parameters:
logFilePath- the base path where container logs will be saved. Use "/" suffix for automatic role-based naming.- Returns:
- the current instance of
StrimziKafkaClusterBuilderfor method chaining
-
withPort
Sets a fixed exposed port for all broker nodes in the cluster.Note: When using multiple brokers, each broker needs a unique port. The first broker will use the specified port, and subsequent brokers will use incrementing port numbers (e.g., if port 9092 is specified for a 3-broker cluster, the brokers will use ports 9092, 9093, and 9094).
- Parameters:
fixedPort- the base fixed port to expose for the first broker- Returns:
- the current instance of
StrimziKafkaClusterBuilderfor method chaining - Throws:
IllegalArgumentException- if the port is less than or equal to 0
-
withBootstrapServers
public StrimziKafkaCluster.StrimziKafkaClusterBuilder withBootstrapServers(Function<StrimziKafkaContainer, String> provider) Assigns a provider function for overriding the bootstrap servers string for all broker nodes.This is useful when you need to customize how the bootstrap servers address is generated, for example when using a shared network with specific hostnames.
- Parameters:
provider- a function that takes aGenericContainerand returns the bootstrap servers string- Returns:
- the current instance of
StrimziKafkaClusterBuilderfor method chaining
-
withContainerCustomizer
public StrimziKafkaCluster.StrimziKafkaClusterBuilder withContainerCustomizer(Consumer<StrimziKafkaContainer> customizer) Assigns a customizer function to modify each Kafka container after its creation. This allows for additional configurations or adjustments to be applied to each container.- Parameters:
customizer- a consumer that takes aGenericContainerfor customization- Returns:
- the current instance of
StrimziKafkaClusterBuilderfor method chaining
-
withOAuthConfig
public StrimziKafkaCluster.StrimziKafkaClusterBuilder withOAuthConfig(String realm, String clientId, String clientSecret, String oauthUri, String usernameClaim) Configures OAuth settings for all nodes in the cluster.- Parameters:
realm- the OAuth realm nameclientId- the OAuth client IDclientSecret- the OAuth client secretoauthUri- the OAuth server URIusernameClaim- the claim to use for the username- Returns:
- the current instance of
StrimziKafkaClusterBuilderfor method chaining
-
withAuthenticationType
public StrimziKafkaCluster.StrimziKafkaClusterBuilder withAuthenticationType(AuthenticationType authType) Sets the authentication type for all nodes in the cluster.- Parameters:
authType- the authentication type to enable- Returns:
- the current instance of
StrimziKafkaClusterBuilderfor method chaining
-
withSaslUsername
Sets the SASL username for OAuth over PLAIN authentication.- Parameters:
saslUsername- the SASL username- Returns:
- the current instance of
StrimziKafkaClusterBuilderfor method chaining - Throws:
IllegalArgumentException- if the username is null or empty
-
withSaslPassword
Sets the SASL password for OAuth over PLAIN authentication.- Parameters:
saslPassword- the SASL password- Returns:
- the current instance of
StrimziKafkaClusterBuilderfor method chaining - Throws:
IllegalArgumentException- if the password is null or empty
-
build
Builds and returns aStrimziKafkaClusterinstance based on the provided configurations.- Returns:
- a new instance of
StrimziKafkaCluster
-