From e8ad3c61328f30d7aa8a4a3bfa7ecb2c4918140d Mon Sep 17 00:00:00 2001 From: damien Date: Sun, 29 Sep 2024 20:18:06 +0200 Subject: [PATCH] 43581 define host.docker.internal with 19092 port for network communication with a kafka connect (likes Debezium) devservice --- .../kafka/client/deployment/KafkaNativeContainer.java | 9 ++++++++- .../kafka/client/deployment/RedpandaKafkaContainer.java | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/KafkaNativeContainer.java b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/KafkaNativeContainer.java index 2381592c4fd5b..b546010eab0b9 100644 --- a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/KafkaNativeContainer.java +++ b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/KafkaNativeContainer.java @@ -22,6 +22,8 @@ public class KafkaNativeContainer extends GenericContainer private int exposedPort = -1; private String hostName = null; + private static final String HOST_DOCKER_INTERNAL = "host.docker.internal"; + private static final int HOST_DOCKER_INTERNAL_PORT = 19092; public KafkaNativeContainer(DockerImageName dockerImageName, int fixedExposedPort, String serviceName, boolean useSharedNetwork) { @@ -47,7 +49,8 @@ protected void containerIsStarting(InspectContainerResponse containerInfo, boole cmd += "/work/kafka"; cmd += " -Dkafka.advertised.listeners=" + getBootstrapServers(); if (useSharedNetwork) { - cmd += " -Dkafka.listeners=BROKER://:9093,PLAINTEXT://:9092,CONTROLLER://:9094"; + cmd += " -Dkafka.listeners=BROKER://:9093,PLAINTEXT://:9092,CONTROLLER://:9094,HOST_DOCKER_INTERNAL://" + + HOST_DOCKER_INTERNAL_PORT; cmd += " -Dkafka.interbroker.listener.name=BROKER"; cmd += " -Dkafka.controller.listener.names=CONTROLLER"; cmd += " -Dkafka.listener.security.protocol.map=BROKER:PLAINTEXT,CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT"; @@ -74,6 +77,10 @@ private String getKafkaAdvertisedListeners() { // See https://github.com/quarkusio/quarkus/issues/21819 // Kafka is always exposed to the Docker host network addresses.add(String.format("PLAINTEXT://%s:%d", getHost(), getExposedKafkaPort())); + // See https://github.com/debezium/debezium/pull/5903 + // need to access kafka from a debezium connect container using + addresses.add( + String.format("HOST_DOCKER_INTERNAL://%s:%d", HOST_DOCKER_INTERNAL, getMappedPort(HOST_DOCKER_INTERNAL_PORT))); return String.join(",", addresses); } diff --git a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/RedpandaKafkaContainer.java b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/RedpandaKafkaContainer.java index 8dca5de6d1c12..0dc89840bf599 100644 --- a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/RedpandaKafkaContainer.java +++ b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/RedpandaKafkaContainer.java @@ -28,6 +28,8 @@ final class RedpandaKafkaContainer extends GenericContainer