生成消息时找不到主题:未知的\u主题\u或\u分区

2guxujil  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(417)

我有一个两节点的kafka集群(ec2示例),其中每个节点用作单独的代理。当我使用以下命令在leader示例上运行producer时:

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

我得到以下错误。
测试消息[2017-01-09 13:22:39483]获取相关id为0的元数据时出现警告错误:{test=unknown\u topic\u or\u partition}(org.apache.kafka.clients.networkclient)[2017-01-09 13:22:39,562]获取相关id为1的元数据时出现警告错误:{test=unknown\u topic\u or\u partition}(org.apache.kafka.clients.networkclient)[2017-01-09 13:22:39663]获取相关id为2的元数据时出现警告错误:{test=unknown\u topic\u or\u partition}(org.apache.kafka.clients.networkclient)。。。
列出主题 kafka-topics.sh 显示主题存在。
主题描述包括:

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

退货

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

我使用的是Kafka0.10.1.1。 server.properties 文件包含:

  1. listeners=PLAINTEXT://0.0.0.0:9092
  2. advertised.listeners=PLAINTEXT://0.0.0.0:9092
  3. port=9092
  4. host.name=kafka-node1(kafka-node1 for the second host)
  5. advertised.host.name=kafka-node1(kafka-node2 for the second host)
  6. advertised.port=9092

当我尝试从第二台主机生成消息时,我得到以下消息:
warn got error在主题分区test-4上生成相关id为1的响应,正在重试(还剩2次尝试)。错误:不是分区(org.apache.kafka.clients.producer.internals.sender)的\u leader\u。。。。
有人能帮忙吗?

mhd8tkvw

mhd8tkvw1#

为主题设置复制因子2 test 你不会再有这种例外了。由于您有一个2 broker群集,请执行以下命令以生成消息:

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

这将向集群中的两个代理发送消息。

相关问题