生成消息时找不到主题:UNKNOWN_TOPIC_OR_PARTITION [英] Topic can't be found when producing messages: UNKNOWN_TOPIC_OR_PARTITION

查看:5310
本文介绍了生成消息时找不到主题:UNKNOWN_TOPIC_OR_PARTITION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个两节点的Kafka集群(EC2实例),其中每个节点都用作单独的代理.当我使用以下命令在leader实例上运行生产者时:

I have a two-nodes Kafka cluster (EC2 instances) where each node is used as a separate broker. When I run a producer on the leader instance with the following command:

kafka-console-producer.sh   --broker-list localhost:9092 --topic test

我遇到以下错误.

测试消息 [2017-01-09 13:22:39,483]提取关联ID为0的元数据时出现警告错误:{test = UNKNOWN_TOPIC_OR_PARTITION}(org.apache.kafka.clients.NetworkClient) [2017-01-09 13:22:39,562]提取关联ID为1的元数据时出现警告错误:{test = UNKNOWN_TOPIC_OR_PARTITION}(org.apache.kafka.clients.NetworkClient) [2017-01-09 13:22:39,663]提取关联ID为2的元数据时出现警告错误:{test = UNKNOWN_TOPIC_OR_PARTITION}(org.apache.kafka.clients.NetworkClient) ...

test message [2017-01-09 13:22:39,483] WARN Error while fetching metadata with correlation id 0 : {test=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient) [2017-01-09 13:22:39,562] WARN Error while fetching metadata with correlation id 1 : {test=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient) [2017-01-09 13:22:39,663] WARN Error while fetching metadata with correlation id 2 : {test=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient) ...

使用kafka-topics.sh列出主题表明主题存在.

Listing the topics with kafka-topics.sh shows that the topic exists.

主题描述:

kafka-topics.sh --zookeeper localhost:2181 --describe --topic test

返回

 Topic:test PartitionCount:8    ReplicationFactor:1 Configs:
     Topic: test    Partition: 0    Leader: 1   Replicas: 1 Isr: 1
     Topic: test    Partition: 1    Leader: 2   Replicas: 2 Isr: 2
     Topic: test    Partition: 2    Leader: 1   Replicas: 1 Isr: 1
     Topic: test    Partition: 3    Leader: 2   Replicas: 2 Isr: 2
     Topic: test    Partition: 4    Leader: 1   Replicas: 1 Isr: 1
     Topic: test    Partition: 5    Leader: 2   Replicas: 2 Isr: 2
     Topic: test    Partition: 6    Leader: 1   Replicas: 1 Isr: 1
     Topic: test    Partition: 7    Leader: 2   Replicas: 2 Isr: 2

我正在使用Kafka 0.10.1.1.

I am using Kafka 0.10.1.1.

server.properties文件包含:

listeners=PLAINTEXT://0.0.0.0:9092
advertised.listeners=PLAINTEXT://0.0.0.0:9092
port=9092
host.name=kafka-node1(kafka-node1 for the second host)
advertised.host.name=kafka-node1(kafka-node2 for the second host)
advertised.port=9092

当我尝试从第二个主机生成消息时,我收到以下消息:

When I try to produce messages from the second host I get the message below:

WARN Got错误产生了相关ID为1的响应 topic-partition test-4,重试(还剩2次尝试).错误: NOT_LEADER_FOR_PARTITION (org.apache.kafka.clients.producer.internals.Sender) ....

WARN Got error produce response with correlation id 1 on topic-partition test-4, retrying (2 attempts left). Error: NOT_LEADER_FOR_PARTITION (org.apache.kafka.clients.producer.internals.Sender) ....

任何人都可以帮忙吗?

推荐答案

为主题test设置复制因子2,您将再也不会遇到此异常. 由于您有2个代理群集,请执行以下命令以生成消息:

Make the replication factor 2 for topic test and you won't get this exception anymore. Since you have a 2 broker cluster, execute the command below to produce messages:

kafka-console-producer.sh   --broker-list localhost:9092,localhost:9093 --topic test

这会将消息发送到集群中的两个代理.

This will send messages to both of the brokers in the clusters.

这篇关于生成消息时找不到主题:UNKNOWN_TOPIC_OR_PARTITION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆