1

I wrote a java based microservice which writes (Producer) to Kafka Queue. When I tested my microservice it is writing the data to Kafka correctly.

These were my settings that worked.

        "bootstrap.servers":"localhost:9092",
        "TOPIC":"my.data",
        "PARTITION":"0",
        "key.deserializer":"org.apache.kafka.common.serialization.StringDeserializer",
        "value.deserializer":"org.apache.kafka.common.serialization.StringDeserializer",
        "enable.auto.commit":"false"

When I installed my microservice on the docker I changed my settings to

        "bootstrap.servers":"host.docker.internal:9092",
        "TOPIC":"my.data",
        "PARTITION":"0",
        "key.deserializer":"org.apache.kafka.common.serialization.StringDeserializer",
        "value.deserializer":"org.apache.kafka.common.serialization.StringDeserializer",
        "enable.auto.commit":"false"

Microservice is failing with the following error.

2020-11-19 18:41:14,958 WARN [org.apa.kaf.cli.NetworkClient] (kafka-producer-network-thread | producer-1) [Producer clientId=producer-1] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
2020-11-19 18:41:14,967 WARN [org.apa.kaf.cli.NetworkClient] (kafka-producer-network-thread | producer-1) [Producer clientId=producer-1] Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected

Am I missing anything? Any help will be appreciated.

techrhl
  • 434
  • 8
  • 19

1 Answers1

0

bootstrap.servers is used for establishing the initial connection to the Kafka cluster. After this connection is established, broker sends advertised.listeners and producer uses this addresses to send messages.

In your case, as it can be seen from logs your advertised.listeners is localhost. That's why your docker container will try to access its own localhost.

Solution: You should also set advertised.listeners config in server.properties file to host.docker.internal:9092 to connect from docker container.

You can check this for more information.

H.Ç.T
  • 3,335
  • 1
  • 18
  • 37