Package org.testcontainers.kafka
Class KafkaContainer
java.lang.Object
org.testcontainers.containers.FailureDetectingExternalResource
org.testcontainers.containers.GenericContainer<KafkaContainer>
org.testcontainers.kafka.KafkaContainer
- All Implemented Interfaces:
AutoCloseable,org.junit.rules.TestRule,org.testcontainers.containers.Container<KafkaContainer>,org.testcontainers.containers.ContainerState,org.testcontainers.containers.traits.LinkableContainer,org.testcontainers.containers.wait.strategy.WaitStrategyTarget,org.testcontainers.lifecycle.Startable
Testcontainers implementation for Apache Kafka.
Supported image: apache/kafka, apache/kafka-native
Exposed ports: 9092
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.testcontainers.containers.Container
org.testcontainers.containers.Container.ExecResult -
Field Summary
Fields inherited from class org.testcontainers.containers.GenericContainer
CONTAINER_RUNNING_TIMEOUT_SEC, dependencies, dockerClient, INTERNAL_HOST_HOSTNAME, waitStrategyFields inherited from interface org.testcontainers.containers.ContainerState
STATE_HEALTHY -
Constructor Summary
ConstructorsConstructorDescriptionKafkaContainer(String imageName) KafkaContainer(org.testcontainers.utility.DockerImageName dockerImageName) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidcontainerIsStarting(com.github.dockerjava.api.command.InspectContainerResponse containerInfo) withListener(String listener) Add a listener in the formathost:port.withListener(String listener, Supplier<String> advertisedListener) Add a listener in the formathost:portand aSupplierfor the advertised listener.Methods inherited from class org.testcontainers.containers.GenericContainer
addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, apply, canBeReused, containerIsCreated, containerIsStarted, containerIsStarted, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, doStart, equals, failed, finished, getBinds, getCommandParts, getContainerId, getContainerInfo, getContainerName, getCopyToFileContainerPathMap, getCreateContainerCmdModifiers, getDependencies, getDockerClient, getDockerImageName, getEnv, getEnvMap, getExposedPorts, getExtraHosts, getImage, getIpAddress, getLabels, getLinkedContainers, getLivenessCheckPort, getLivenessCheckPortNumbers, getLivenessCheckPorts, getLogConsumers, getNetwork, getNetworkAliases, getNetworkMode, getPortBindings, getShmSize, getStartupAttempts, getStartupCheckStrategy, getTestHostIpAddress, getTmpFsMapping, getVolumesFroms, getWaitStrategy, getWorkingDirectory, hashCode, isHostAccessible, isPrivilegedMode, isShouldBeReused, logger, setBinds, setCommand, setCommand, setCommandParts, setContainerDef, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExposedPorts, setExtraHosts, setHostAccessible, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWaitStrategy, setWorkingDirectory, start, starting, stop, succeeded, toString, waitingFor, waitUntilContainerStarted, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withReuse, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withStartupTimeout, withTmpFs, withVolumesFrom, withWorkingDirectoryMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.testcontainers.containers.Container
addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBindMethods inherited from interface org.testcontainers.containers.ContainerState
copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunningMethods inherited from interface org.testcontainers.lifecycle.Startable
close
-
Constructor Details
-
KafkaContainer
-
KafkaContainer
public KafkaContainer(org.testcontainers.utility.DockerImageName dockerImageName)
-
-
Method Details
-
configure
protected void configure()- Overrides:
configurein classorg.testcontainers.containers.GenericContainer<KafkaContainer>
-
containerIsStarting
protected void containerIsStarting(com.github.dockerjava.api.command.InspectContainerResponse containerInfo) - Overrides:
containerIsStartingin classorg.testcontainers.containers.GenericContainer<KafkaContainer>
-
withListener
Add a listener in the formathost:port. Host will be included as a network alias.Use it to register additional connections to the Kafka broker within the same container network.
The listener will be added to the list of default listeners.
Default listeners:
- 0.0.0.0:9092
- 0.0.0.0:9093
- 0.0.0.0:9094
The listener will be added to the list of default advertised listeners.
Default advertised listeners:
container.getConfig().getHostName():9092container.getHost():container.getMappedPort(9093)
- Parameters:
listener- a listener with formathost:port- Returns:
- this
KafkaContainerinstance
-
withListener
Add a listener in the formathost:portand aSupplierfor the advertised listener. Host from listener will be included as a network alias.Use it to register additional connections to the Kafka broker from outside the container network
The listener will be added to the list of default listeners.
Default listeners:
- 0.0.0.0:9092
- 0.0.0.0:9093
- 0.0.0.0:9094
The
Supplierwill be added to the list of default advertised listeners.Default advertised listeners:
container.getConfig().getHostName():9092container.getHost():container.getMappedPort(9093)
- Parameters:
listener- a supplier that will provide a listeneradvertisedListener- a supplier that will provide a listener- Returns:
- this
KafkaContainerinstance
-
getBootstrapServers
-