我有一个双节点kafka集群(EC2实例),其中每个节点都用作单独的代理。当我使用以下命令在leader实例上运行生产者时:
kafka-console-producer.sh --broker-list localhost:9092 --topic test
我收到以下错误。
测试消息 [2017-01-09 13:22:39,483] WARN在获取具有相关ID 0的元数据时出错:{test = UNKNOWN_TOPIC_OR_PARTITION}(org.apache.kafka.clients.NetworkClient) [2017-01-09 13:22:39,562] WARN获取具有相关ID 1的元数据时出错:{test = UNKNOWN_TOPIC_OR_PARTITION}(org.apache.kafka.clients.NetworkClient) [2017-01-09 13:22:39,663] WARN在获取具有相关ID 2的元数据时出错:{test = UNKNOWN_TOPIC_OR_PARTITION}(org.apache.kafka.clients.NetworkClient) ...
列出kaka-topics.sh
主题,表明主题存在。
主题描述:
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。
server.propertes
文件包含:
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
当我尝试从第二台主机发出消息时,我收到以下消息:
警告错误产生响应且相关ID为1 topic-partition test-4,重试(剩下2次尝试)。错误: NOT_LEADER_FOR_PARTITION (org.apache.kafka.clients.producer.internals.Sender) ....
有人可以帮忙吗? 感谢。
答案 0 :(得分:3)
为主题test
创建复制因子2,您将不再获得此异常。
由于您有2个代理群集,请执行以下命令以生成消息:
kafka-console-producer.sh --broker-list localhost:9092,localhost:9093 --topic test
这将向群集中的两个代理发送消息。
答案 1 :(得分:1)
如果您获得 UNKNOWN_TOPIC_OR_PARTITION
,请将以下属性添加到 server.properties
文件:
listeners=PLAINTEXT://host.name:port
advertised.listeners=PLAINTEXT://host.name:port
在我的情况下,值如下:
listeners=PLAINTEXT://localhost:9092
advertised.listeners=PLAINTEXT://localhost:9092
答案 2 :(得分:0)
您的主题已标记为删除:
KAFKA_OPTS="-Djava.security.auth.login.config=/home/kafka/kafka_2.11-1.0.0/config/jaas.conf -Djava.security.krb5.conf=/etc/krb5.conf" \
bin/kafka-topics.sh --describe \
--zookeeper zookeeper-server-01.eigenroute.com:2181,zookeeper-server-02.eigenroute.com:2181,zookeeper-server-03.eigenroute.com:2181/apps/kafka-cluster-demo
Topic:another-test-topic PartitionCount:9 ReplicationFactor:2 Configs: MarkedForDeletion:true
Topic: another-test-topic Partition: 0 Leader: none Replicas: 2,1 Isr:
Topic: another-test-topic Partition: 1 Leader: none Replicas: 1,2 Isr:
Topic: another-test-topic Partition: 2 Leader: none Replicas: 2,1 Isr:
...