提取具有相关性ID 74的元数据时出错:{topicC = LEADER_NOT_AVAILABLE}

时间:2019-09-02 09:34:18

标签: docker apache-kafka

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

这是我的代码: 我在docker上创建了一些容器,只需使用jdk镜像即可。

三个动物园管理员容器

zookeeper00zookeeper01zookeeper02

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容器

kafka00kafka01kafka02

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}

能否请您指出问题,谢谢!

1 个答案:

答案 0 :(得分:0)

我通过添加另一个端口侦听来解决该问题。这是我的 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