简体   繁体   中英

Apache Kafka Topic metadata fetch included errors: {LEADER_NOT_AVAILABLE}

I'm trying to do dockerfile which has wurstmeister/zookeeper and wurstmeister/kafka. If I run consumer and producer on my computer everything works correctly ( I'm running zookeeper and kafka on terminal) .But when I use this zookeper and kafka I mean when I run this dockerfile, I got this error

o.a.k.c.consumer.internals.Fetcher - [Consumer clientId=consumer-1, groupId=consumerGroup1] Topic metadata fetch included errors: {log-monitoring=LEADER_NOT_AVAILABLE}

I think the problem about networking, they can't find each other on docker. This is my docker-compose.yml

zookeeper:
  image: wurstmeister/zookeeper
  container_name: "zk"
  ports:
    - "2181:2181"
kafka:
  image: wurstmeister/kafka
  container_name: "kafka"
  ports:
    - "9092:9092"
  environment:
    KAFKA_ADVERTISED_HOST_NAME: 192.168.99.100
    KAFKA_ZOOKEEPER_CONNECT: zk:2181
    KAFKA_CREATE_TOPICS: "log-monitoring"
  links:
    - zookeeper:zk
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
mongo:
  image: mongo
  container_name: "mongo"
  ports:
    - "27017:27017"

producer:
  image: berat703/kafka-producer:0.0.3
  container_name: "producer"
  environment:
    - KAFKA_BROKER=kafka:9092
  links:
    - kafka:kafka
consumer:
  image: berat703/kafka-consumer:0.0.2
  container_name: "consumer"
  ports:
    - "8080:8080"
  environment:
    - KAFKA_BROKER=kafka:9092
    - MONGODB_HOST=mongo
    - MONGODB_PORT=27017
  links:
    - kafka:kafka

Try changing KAFKA_ADVERTISED_HOST_NAME to kafka's FQDN ie. kafka . Whatever you put there needs to be resolvable by the producer. That field is also deprecated, it's recommended to use something like KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092 instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM