• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring Boot - Kafka Issue running on Docker (Bootstrap broker localhost:9092 disconnected)

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a problem to run Spring Boot CQRS example on Docker.

When I run this command `docker-compose up --build`, all containers are up.

I got this issue when I sent any request from postman collection in my repo.

   account-cmd -> Bootstrap broker localhost:9092 disconnected
   account-query -> Bootstrap broker localhost:9092 disconnected

Here are the screenshots shown below

[![Image 1][1]][1]
[![Image 2][2]][2]

Here is the docker-compose.yml shown below

   version: '3.9'
   
   services:
     account-cmd:
       image: 'account-cmd:latest'
       build:
         context: ./account.cmd
       ports:
         - "5000:5000"
       depends_on:
         - zookeeper
         - kafka
         - mongodb
       environment:
         - kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
         - kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer
         - spring.data.mongodb.host=mongodb
         - spring.data.mongodb.port=27017
         - spring.data.mongodb.database=bankAccount
         - server.port=5000
       networks:
         - bankAccount
   
     account-query:
       image: 'account-query:latest'
       build:
         context: ./account.query
       ports:
         - "5001:5001"
       depends_on:
         - zookeeper
         - kafka
         - database
       environment:
         - spring.datasource.url=jdbc:mysql://database:3306/bankAccount?createDatabaseIfNotExist=true&useSSL=false&allowPublicKeyRetrieval=true
         - server.port=5001
         - spring.datasource.username=root
         - spring.datasource.password=ippavlova_1990
         - spring.kafka.consumer.group-id=bankaccConsumer
         - spring.kafka.consumer.auto-offset-reset=earliest
         - spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
         - spring.kafka.consumer.value-deserializer=org.springframework.kafka.support.serializer.JsonDeserializer
         - spring.kafka.consumer.properties.spring.json.trusted.packages=*
       networks:
         - bankAccount
   
     database:
       container_name: mysql-database
       image: 'mysql:latest'
       ports:
         - "3306:3306"
       restart: always
       environment:
         MYSQL_PASSWORD: ippavlova_1990
         MYSQL_ROOT_PASSWORD: ippavlova_1990
       volumes:
         - db-data:/var/lib/mysql
       networks:
         - bankAccount
       healthcheck:
         test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
         timeout: 20s
         retries: 10
   
   
     mongodb:
       image: "mongo:latest"
       container_name: mongo-container
       restart: always
       ports:
         - "27017:27017"
       volumes:
         - mongodb_data_container:/data/db
       networks:
         - bankAccount
   
     zookeeper:
       image: 'bitnami/zookeeper:latest'
       restart: always
       ports:
         - "2181:2181"
       volumes:
         - "zookeeper_data:/bitnami"
       environment:
         - ALLOW_ANONYMOUS_LOGIN=yes
       networks:
         - bankAccount
   
     kafka:
       image: 'bitnami/kafka:latest'
       ports:
         - '9092:9092'
       environment:
         - KAFKA_BROKER_ID=1
         - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
         - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092
         - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
         - ALLOW_PLAINTEXT_LISTENER=yes
       depends_on:
         - zookeeper
       networks:
         - bankAccount
   
   
   volumes:
     mongodb_data_container:
     db-data:
     zookeeper_data:
       driver: local
     kafka_data:
       driver: local
   
   networks:
     bankAccount:


Here is the repo : [Link][3]


 [1]: https://i.stack.imgur.com/7Bbw4.png
 [2]: https://i.stack.imgur.com/QlYlD.png
 [3]: https://github.com/Rapter1990/cqrs-example
 
Bartender
Posts: 2419
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you need a bridge :
For example:
networks:
 kafka-net:
   name: kafka-net
   driver: bridge

services:
 zookeeper:
   image: docker.io/bitnami/zookeeper:3.8
   container_name: zookeeper
   
   networks:
     - kafka-net
   ports:
     - "2181:2181"
    ...
 kafka:
   image: docker.io/bitnami/kafka:3
   container_name: kafka
   networks:
     - kafka-net
   ports:
     - "9092:9092"
  environment:
     ...
   depends_on:
     - zookeeper
 
Kevin Rapter
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It didn't help me solve the issue. Can you test it?


networks:
 bankAccount:
    driver: bridge
 
Kevin Rapter
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Himai Minh wrote:I think you need a bridge :
For example:
networks:
 kafka-net:
   name: kafka-net
   driver: bridge

services:
 zookeeper:
   image: docker.io/bitnami/zookeeper:3.8
   container_name: zookeeper
   
   networks:
     - kafka-net
   ports:
     - "2181:2181"
    ...
 kafka:
   image: docker.io/bitnami/kafka:3
   container_name: kafka
   networks:
     - kafka-net
   ports:
     - "9092:9092"
  environment:
     ...
   depends_on:
     - zookeeper



It didn't help me solve the issue. Can you test it?


networks:
bankAccount:
   driver: bridge
 
Himai Minh
Bartender
Posts: 2419
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add name attribute like this ?
networks:
bankAccount:
 name: bankAccount
  driver: bridge
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic