Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected

muradazimzada
Tue, 19 Nov 2024 02:45:06 +0000
General

Hi,

I have been trying to get my dockerized services up, however I am facing some issues with connecting to kafka broker (docker-container) from java applications.

What I have tried: setting bootstrap server to kafka, localhost, ip address of the machine - non of them worked.

I was able to connect to kafka broker from the java (spring boot) app when I had the broker installed on Ubuntu OS and the spring boot app was build and ran not as containerized.

I am trying it on Windows, and Ubuntu.

So my docker-compose.yml is as below:

services:
  zookeeper:
    image: confluentinc/cp-zookeeper:latest
    container_name: zookeeper
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    ports:
      - "2181:2181"
    networks:
      - kafka-network

  kafka:
    image: confluentinc/cp-kafka:latest
    container_name: kafka
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
    ports:
      - "9092:9092"
    depends_on:
      - zookeeper
    networks:
      - kafka-network
    volumes:
      - kafka-data:/var/lib/kafka/data  # New volume for Kafka data
      - kafka-streams-state:/var/lib/kafka/streams  # New volume for Kafka Streams state

  job-jays-api:
    build:
        context: ../
        dockerfile: Dockerfile
    container_name: job-jays-api
    ports:
      - "8080:8080"
    networks:
      - kafka-network
  applicant-job-matcher:
    build:
      context: ../applicant_job_matcher
      dockerfile: Dockerfile
    container_name: applicant-job-matcher
    depends_on:
      - job-jays-api
    networks:
      - kafka-network
  preference-updater:
    build:
      context: ../preference_updater
      dockerfile: Dockerfile
    container_name: preference-updater
    depends_on:
      - job-jays-api
    networks:
      - kafka-network
  notification-sender:
    build:
      context: ../notification_sender
      dockerfile: Dockerfile
    container_name: notification-sender
    depends_on:
      - job-jays-api
    networks:
      - kafka-network

networks:
  kafka-network:
    driver: bridge

volumes:
  kafka-data:
  kafka-streams-state:

2 posts - 2 participants