Skip to content

Commit

Permalink
use standard port 9092 in KafkaContainer (#733)
Browse files Browse the repository at this point in the history
* use standard port 9092 in KafkaContainer

* use constants where possible
  • Loading branch information
bsideup committed Jun 11, 2018
1 parent 3b974e9 commit acf904d
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public class KafkaContainer extends GenericContainer<KafkaContainer> {

public static final int KAFKA_PORT = 9092;
public static final int KAFKA_PORT = 9093;

public static final int ZOOKEEPER_PORT = 2181;

Expand All @@ -27,13 +27,12 @@ public KafkaContainer(String confluentPlatformVersion) {
super(TestcontainersConfiguration.getInstance().getKafkaImage() + ":" + confluentPlatformVersion);

withNetwork(Network.newNetwork());
String networkAlias = "kafka-" + Base58.randomString(6);
withNetworkAliases(networkAlias);
withNetworkAliases("kafka-" + Base58.randomString(6));
withExposedPorts(KAFKA_PORT);

// Use two listeners with different names, it will force Kafka to communicate with itself via internal
// listener when KAFKA_INTER_BROKER_LISTENER_NAME is set, otherwise Kafka will try to use the advertised listener
withEnv("KAFKA_LISTENERS", "PLAINTEXT://0.0.0.0:9092,BROKER://" + networkAlias + ":9093");
withEnv("KAFKA_LISTENERS", "PLAINTEXT://0.0.0.0:" + KAFKA_PORT + ",BROKER://0.0.0.0:9092");
withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "BROKER:PLAINTEXT,PLAINTEXT:PLAINTEXT");
withEnv("KAFKA_INTER_BROKER_LISTENER_NAME", "BROKER");

Expand Down Expand Up @@ -62,11 +61,11 @@ public void start() {
String networkAlias = getNetworkAliases().get(0);
proxy = new SocatContainer()
.withNetwork(getNetwork())
.withTarget(9092, networkAlias)
.withTarget(2181, networkAlias);
.withTarget(KAFKA_PORT, networkAlias)
.withTarget(ZOOKEEPER_PORT, networkAlias);

proxy.start();
withEnv("KAFKA_ADVERTISED_LISTENERS", "BROKER://" + networkAlias + ":9093,PLAINTEXT://" + proxy.getContainerIpAddress() + ":" + proxy.getFirstMappedPort());
withEnv("KAFKA_ADVERTISED_LISTENERS", "BROKER://" + networkAlias + ":" + KAFKA_PORT +",PLAINTEXT://" + proxy.getContainerIpAddress() + ":" + proxy.getFirstMappedPort());

if (externalZookeeperConnect != null) {
withEnv("KAFKA_ZOOKEEPER_CONNECT", externalZookeeperConnect);
Expand Down

0 comments on commit acf904d

Please sign in to comment.