一尘不染

为什么卡夫卡会警告“分区中的领导经纪人没有匹配的听众”?

docker

我正在尝试让Kafka第一次在docker-
compose上工作。该应用程序在没有docker的情况下运行良好。但是在docker上,出现如下所述的错误。卡夫卡为何会抛出此错误?

错误:

email-service_1 | 2018-12-01 14:32:02.448警告1 — [ntainer#0-0-C-1]
oakcNetworkClient:[Consumer clientId = consumer-2,groupId = kafka]
1个分区的领导者经纪人没有匹配的侦听器,包括[email-token-0]

我的docker-compose配置:

version: '3.3'
    services:
     zookeeper:
      image: wurstmeister/zookeeper
      ports:
       - "2181:2181"

 kafka:
  image: wurstmeister/kafka
  command: [start-kafka.sh]
  environment:
   KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
   KAFKA_ADVERTISED_HOST_NAME: 192.168.23.134
   KAFKA_CREATE_TOPICS: "email-token:1:1"
  volumes:
   - /var/run/docker.sock:/var/run/docker.sock
  ports:
   - "9092:9092"
  depends_on:
   - zookeeper

 email-service:
  build: ./email-service
  environment:
   SPRING_KAFKA_BOOTSTRAPSERVERS: kafka:9092
  ports:
   - "8081:8081"
  depends_on:
   - kafka

阅读 402

收藏
2020-06-17

共1个答案

一尘不染

如对您的问题的评论所述,问题似乎出在Kafka经纪人的广告名称上。根据您的docker-
compose,您应该使用,192.168.23.134但您的电子邮件服务正在使用kafka:9092。您可以尝试使用此docker-
compose。我用提供的最新Zookeeper和Kafka替换了wurstmeister服务,confluentinc并添加了您的电子邮件服务。

---
version: '2'
services:
zookeeper:
    image: confluentinc/cp-zookeeper:latest
    environment:
    ZOOKEEPER_CLIENT_PORT: 2181
    ZOOKEEPER_TICK_TIME: 2000

kafka:
    image: confluentinc/cp-kafka:latest
    depends_on:
    - zookeeper
    ports:
    - 9092:9092
    environment:
    KAFKA_BROKER_ID: 1
    KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
    KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
    KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
    KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

email-service:
  build: ./email-service
  environment:
   SPRING_KAFKA_BOOTSTRAPSERVERS: kafka:29092
  ports:
   - "8081:8081"
  depends_on:
   - kafka

advertised.listeners :发布到ZooKeeper以便客户端使用的监听器,如果与listeners
config属性不同。在IaaS环境中,这可能需要与代理绑定的接口不同。如果未设置,将使用侦听器的值。与侦听器不同,宣告0.0.0.0元地址无效。

请注意,它KAFKA_ADVERTISED_HOST_NAME已被弃用,建议改为使用KAFKA_ADVERTISED_LISTENERS。有关更多信息,KAFKA_ADVERTISED_LISTENERS在此处检查。

2020-06-17