0

here is my docker-compose file for Kafka. It is essential to run this on port other than 9092 so that I can have other Kafka instance in docker mapped to 9092. So I decided to go with 9093.

version: "2"

services:
  kafka_project_zookeeper:
    image: "docker.io/bitnami/zookeeper:3"
    ports:
      - "22181:2181"
    volumes:
      - "kafka_project_zookeeper_data:/bitnami"
    environment:
      ALLOW_ANONYMOUS_LOGIN: "yes"
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
  kafka_project_dbpostgres:
    image: postgres
    shm_size: 2g
    volumes:
      - /var/lib/kafkaproject_postgresql:/var/lib/postgresql
    ports:
      - "5433:5432"
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: kafkaproject
  kafka_project_kafka:
    image: "docker.io/bitnami/kafka:2-debian-10"
    ports:
      - "9093:9092"
    volumes:
      - "kafkaproject_data:/bitnami"
    environment:
      - KAFKA_LISTENERS=PLAINTEXT://:9093
      - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9093
      - KAFKA_ZOOKEEPER_CONNECT=kafka_project_zookeeper:2181
      - ALLOW_PLAINTEXT_LISTENER=yes
    depends_on:
      - kafka_project_zookeeper

volumes:
  kafka_project_zookeeper_data:
    driver: local
  kafkaproject_data:
    driver: local

Problem is that container starts but spring boot app is failed to load topics list and finally app exit:

2022-04-22 15:27:31.941  INFO 11727 --- [           main] o.a.kafka.common.utils.AppInfoParser     : Kafka version: 3.0.0
2022-04-22 15:27:31.941  INFO 11727 --- [           main] o.a.kafka.common.utils.AppInfoParser     : Kafka commitId: 8cb0a5e9d3441962
2022-04-22 15:27:31.941  INFO 11727 --- [           main] o.a.kafka.common.utils.AppInfoParser     : Kafka startTimeMs: 1650634051939
2022-04-22 15:28:01.948  INFO 11727 --- [| adminclient-1] o.a.k.c.a.i.AdminMetadataManager         : [AdminClient clientId=adminclient-1] Metadata update failed

org.apache.kafka.common.errors.TimeoutException: Timed out waiting to send the call. Call: fetchMetadata

2022-04-22 15:28:01.952 ERROR 11727 --- [           main] o.springframework.kafka.core.KafkaAdmin  : Could not configure topics

org.springframework.kafka.KafkaException: Timed out waiting to get existing topics; nested exception is java.util.concurrent.TimeoutException
    at org.springframework.kafka.core.KafkaAdmin.lambda$checkPartitions$5(KafkaAdmin.java:275) ~[spring-kafka-2.8.1.jar:2.8.1]
    at java.base/java.util.HashMap.forEach(HashMap.java:1337) ~[na:na]
    at org.springframework.kafka.core.KafkaAdmin.checkPartitions(KafkaAdmin.java:254) ~[spring-kafka-2.8.1.jar:2.8.1]
    at org.springframework.kafka.core.KafkaAdmin.addOrModifyTopicsIfNeeded(KafkaAdmin.java:240) ~[spring-kafka-2.8.1.jar:2.8.1]
    at org.springframework.kafka.core.KafkaAdmin.initialize(KafkaAdmin.java:178) ~[spring-kafka-2.8.1.jar:2.8.1]
    at org.springframework.kafka.core.KafkaAdmin.afterSingletonsInstantiated(KafkaAdmin.java:145) ~[spring-kafka-2.8.1.jar:2.8.1]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:972) ~[spring-beans-5.3.14.jar:5.3.14]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.14.jar:5.3.14]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.14.jar:5.3.14]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.2.jar:2.6.2]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-2.6.2.jar:2.6.2]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.6.2.jar:2.6.2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.2.jar:2.6.2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.2.jar:2.6.2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.2.jar:2.6.2]
    at com.mis.kafkademo.KafkademoApplication.main(KafkademoApplication.java:17) ~[main/:na]
Caused by: java.util.concurrent.TimeoutException: null
    at java.base/java.util.concurrent.CompletableFuture.timedGet(CompletableFuture.java:1886) ~[na:na]
    at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2021) ~[na:na]
    at org.apache.kafka.common.internals.KafkaFutureImpl.get(KafkaFutureImpl.java:180) ~[kafka-clients-3.0.0.jar:na]
    at org.springframework.kafka.core.KafkaAdmin.lambda$checkPartitions$5(KafkaAdmin.java:257) ~[spring-kafka-2.8.1.jar:2.8.1]
    ... 15 common frames omitted

2022-04-22 15:28:11.953  INFO 11727 --- [| adminclient-1] o.a.k.clients.admin.KafkaAdminClient     : [AdminClient clientId=adminclient-1] Forcing a hard I/O thread shutdown. Requests in progress will be aborted.
2022-04-22 15:28:11.954  INFO 11727 --- [| adminclient-1] o.a.kafka.common.utils.AppInfoParser     : App info kafka.admin.client for adminclient-1 unregistered
2022-04-22 15:28:11.954  INFO 11727 --- [| adminclient-1] o.a.k.c.a.i.AdminMetadataManager         : [AdminClient clientId=adminclient-1] Metadata update failed
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Michał S
  • 93
  • 5
  • 1
    `"9093:9092"` opens port 9093 on your host, but there is nothing running on port 9092 in the container. You should change that to `"9093:9093"` based on your environment variables. Also note: There is no real point in having multiple brokers on the same machine – OneCricketeer Apr 22 '22 at 16:05
  • can you show, your spring-boot code ? – Andre Kouame Apr 24 '22 at 03:43
  • you must replace the 127.0.0.1 by your the adress ip of your computer.you may get this adress by do ifconfig, if your computer run on linux – Andre Kouame Apr 24 '22 at 03:45
  • @AndreKouame That is only needed if the code is actually running on a different computer, not the same host – OneCricketeer Apr 25 '22 at 16:41
  • Try to replace - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9093 by - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://ip_host:9093 – Andre Kouame Apr 27 '22 at 04:19

0 Answers0