生成消息时找不到主题:UNKNOWN_TOPIC_OR_PARTITION [英] Topic can't be found when producing messages: UNKNOWN_TOPIC_OR_PARTITION
问题描述
我有一个两节点的 Kafka 集群(EC2 实例),其中每个节点都用作单独的代理.当我使用以下命令在领导者实例上运行生产者时:
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 有错误产生响应,相关 ID 为 1主题分区测试 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) ....
有人可以帮忙吗?
推荐答案
如果你得到 UNKNOWN_TOPIC_OR_PARTITION
然后将以下属性添加到 server.properties
文件:
If you are getting UNKNOWN_TOPIC_OR_PARTITION
then add the below properties to server.properties
file :
listeners=PLAINTEXT://host.name:port
advertised.listeners=PLAINTEXT://host.name:port
在我的情况下,值如下:
in my cases values were as follows:
listeners=PLAINTEXT://localhost:9092
advertised.listeners=PLAINTEXT://localhost:9092
这篇关于生成消息时找不到主题:UNKNOWN_TOPIC_OR_PARTITION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!