【问题标题】:Error while fetching metadata with correlation id 74 : {topicC=LEADER_NOT_AVAILABLE}获取相关 ID 为 74 的元数据时出错:{topicC=LEADER_NOT_AVAILABLE}
【发布时间】:2020-01-05 08:26:21
【问题描述】:

Error while fetching metadata with correlation id 74 : {topicC=LEADER_NOT_AVAILABLE} 当我向某个主题发送新闻时。

这是我的代码: 我在 docker 创建了一些容器,只使用 jdk 映像。

三个 zookeeper 容器

zookeeper00,zookeeper01,zookeeper02

dataDir=/data/config
clientPort=2181
maxClientCnxns=0
syncLimit=5
server.1=zookeeper00:2888:3888
server.2=zookeeper01:2888:3888
server.3=zookeeper02:2888:3888
initLimit=10
docker run -d --name zookeeper00 --network andy --network-alias zookeeper00 -p 2181:2181 ...

三个 kafka 容器

kafka00,kafka01,kafka02

broker.id=0
listeners=PLAINTEXT://kafka00:9092
advertised.listeners=PLAINTEXT://database_host:9092
zookeeper.connect=zookeeper00:2181,zookeeper01:2181,zookeeper02:2181

我在 windows 的 hosts 文件中添加了 192.168.153.131 database_host192.168.153.131是我的centos IP

docker run -d --name kafka00 --network andy --network-alias kafka00 -p 9092:9092 ...

然后

docker exec -it kafka00 bash

我创建了一个主题,但是当我发送一些消息时,它抛出了Error while fetching metadata with correlation id 38 : {topicC=LEADER_NOT_AVAILABLE}

root@2c9e266d16a2:/# bash /data/kafka/bin/kafka-topics.sh --create --zookeeper zookeeper00:2181 --replication-factor 2 --partitions 2 --topic topicC
Created topic topicC.
root@0613111ca4db:/# bash /data/kafka/bin/kafka-topics.sh --zookeeper zookeeper00:2181 --describe --topic topicC
Topic:topicC    PartitionCount:2        ReplicationFactor:2     Configs:
        Topic: topicC   Partition: 0    Leader: 2       Replicas: 2,0   Isr: 2
        Topic: topicC   Partition: 1    Leader: 1       Replicas: 0,1   Isr: 1
root@0613111ca4db:/# bash /data/kafka/bin/kafka-console-producer.sh --broker-list kafka00:9092 --topic topicC
>test message
[2019-09-02 09:13:16,969] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 38 : {topicC=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2019-09-02 09:13:17,073] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 39 : {topicC=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2019-09-02 09:13:17,182] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 40 : {topicC=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
...

当我在 java 中发送消息时,它也会抛出同样的错误。

final Properties p = new Properties();
p.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"DATABASE_HOST:9092,DATABASE_HOST:9093,DATABASE_HOST:9094");
p.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
p.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class);
p.put(ProducerConfig.CLIENT_ID_CONFIG,"producer-aa-1");
p.put(ProducerConfig.ACKS_CONFIG,"all");
producer = new KafkaProducer<>(p);
producer.send(new ProducerRecord<>(topicName, "a04", "test-msg-a04"));
Sending metadata request (type=MetadataRequest, topics=topicC) to node DATABASE_HOST:9093 (id: -2 rack: null)
Error while fetching metadata with correlation id 4 : {topicC=LEADER_NOT_AVAILABLE}

能否指出问题,谢谢!

【问题讨论】:

    标签: docker apache-kafka


    【解决方案1】:

    我通过添加另一个端口监听解决了这个问题。这是我的 server.properties

    broker.id=1
    listener.security.protocol.map=INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
    advertised.listeners=INSIDE://kafka00:9092,OUTSIDE://database_host:19090
    listeners=INSIDE://:9092,OUTSIDE://:19090
    inter.broker.listener.name=INSIDE
    zookeeper.connect=zookeeper00:2181,zookeeper01:2181,zookeeper02:2181
    

    来自https://stackoverflow.com/a/55649654/10417592

    【讨论】:

      猜你喜欢
      • 2020-12-27
      • 2016-10-20
      • 2019-10-06
      • 1970-01-01
      • 1970-01-01
      • 2020-07-21
      • 2016-07-26
      • 2020-05-15
      • 1970-01-01
      相关资源
      最近更新 更多