0

I'm running kafka using docker-compose.yml. The content of my docker-compose.yml is:

version: "3.8"
name: "event-driven-systems"
services:
  kafka:
    container_name: "kafka"
    image: "bitnami/kafka:latest"
    networks:
      - internal
    ports:
      - "9092:9092"
    volumes:
      - "kafka_data:/bitnami"
    environment:
      - KAFKA_CFG_NODE_ID=0
      - KAFKA_CFG_PROCESS_ROLES=controller,broker
      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
      - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@kafka:9093
      - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
networks:
  internal:
    driver: "bridge"
volumes:
  kafka_data:
    driver: local

I'm using spring's kafka dependency to connect to the running kafka service. In this application.yml file of spring boot I'm having this:

kafka-topic:
  name: "location-update-topic"

spring:
  kafka:
    producer:
      bootstrap-servers: "localhost:9092"
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: org.apache.kafka.common.serialization.StringSerializer

server:
  port: 8081

But I'm getting this error:

2023-08-30T20:54:01.884+05:30  WARN 263120 --- [| adminclient-1] org.apache.kafka.clients.NetworkClient   : [AdminClient clientId=adminclient-1] Error connecting to node 596afe8fbe94:9092 (id: 0 rack: null)

java.net.UnknownHostException: 596afe8fbe94
at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:801) ~[na:na]
        at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1524) ~[na:na]
        at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1381) ~[na:na]
        at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1305) ~[na:na]
        at org.apache.kafka.clients.DefaultHostResolver.resolve(DefaultHostResolver.java:27) ~[kafka-clients-3.4.1.jar:na]
        at org.apache.kafka.clients.ClientUtils.resolve(ClientUtils.java:110) ~[kafka-clients-3.4.1.jar:na]
...

How to solve this issue. I'm using kafka for the first time.

  • 2
    I believe you will need to set `KAFKA_CFG_ADVERTISED_LISTENERS`; otherwise the advertised listeners will get the internal host name. https://hub.docker.com/r/bitnami/kafka/ The kafka-clients first connect to the bootstrap server(s) and the cluster then tells the clients to connect to the advertised listeners. – Gary Russell Aug 30 '23 at 17:52
  • `KAFKA_CFG_ADVERTISED_LISTENERS` specifies the address which your app should use to connect to the broker. It should specify `localhost:9092` since this is the address of your local kafka instance. – jcz Aug 30 '23 at 21:00

0 Answers0