Skip to content

Commit db4cdbb

Browse files
committed
KAFKA_BROKER_ID
1 parent dc14240 commit db4cdbb

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

docs/modules/kafka.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ Create a `KafkaContainer` to use it in your tests:
5656

5757
### withNetworkAliases
5858

59-
The first alias host name defined using `withNetworkAliases` configures port 9092. Example for `kafka:9092`:
59+
The first alias host name defined using `withNetworkAliases` configures port 9092 on the network set by `withNetwork`. Example for `kafka:9092`:
6060

6161
<!--codeinclude-->
6262
[Creating a KafkaContainer](../../modules/kafka/src/test/java/org/testcontainers/kafka/KafkaContainerTest.java) inside_block:registerAlias
6363
<!--/codeinclude-->
6464

6565
This works with `org.testcontainers.kafka.KafkaContainer` and `org.testcontainers.kafka.ConfluentKafkaContainer` but not with deprecated `org.testcontainers.containers.KafkaContainer`.
6666

67-
It only works if `withListener` is not used.
67+
It only works if `withListener` is not used and `KAFKA_BROKER_ID` environment variable is not set.
6868

6969
## Options
7070

modules/kafka/src/main/java/org/testcontainers/kafka/ConfluentKafkaContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected void configure() {
5050
protected void containerIsStarting(InspectContainerResponse containerInfo) {
5151
List<String> networkAliases = getNetworkAliases();
5252
String plaintextAdvertisedListener;
53-
if (listeners.isEmpty() && networkAliases.size() > 1) {
53+
if (!getEnvMap().containsKey("KAFKA_BROKER_ID") && listeners.isEmpty() && networkAliases.size() > 1) {
5454
// 0 is the random network alias generated by GenericContainer
5555
plaintextAdvertisedListener = "PLAINTEXT://" + networkAliases.get(1) + ":" + KafkaHelper.KAFKA_PORT;
5656
} else {

modules/kafka/src/main/java/org/testcontainers/kafka/KafkaContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected void configure() {
5656
protected void containerIsStarting(InspectContainerResponse containerInfo) {
5757
List<String> networkAliases = getNetworkAliases();
5858
String plaintextAdvertisedListener;
59-
if (listeners.isEmpty() && networkAliases.size() > 1) {
59+
if (!getEnvMap().containsKey("KAFKA_BROKER_ID") && listeners.isEmpty() && networkAliases.size() > 1) {
6060
// 0 is the random network alias generated by GenericContainer
6161
plaintextAdvertisedListener = "PLAINTEXT://" + networkAliases.get(1) + ":" + KafkaHelper.KAFKA_PORT;
6262
} else {

0 commit comments

Comments
 (0)