简体   繁体   English

当发送到通过AdminClient createTopics方法创建的主题时,Kafka生产者抛出“接收到的未知主题或分区错误”

[英]Kafka producer throws “Received unknown topic or partition error” when sending to topic created via AdminClient createTopics method

I have issue with topics created using AdminClient createTopics . 我对使用AdminClient createTopics创建的主题有疑问。 In my application I have following sequence: 在我的应用程序中,我有以下顺序:

  1. create new topic with 1 partition, replication factor set to 1 using AdminClient.createTopics 使用1个分区创建新主题,使用AdminClient.createTopics将复制因子设置为1
  2. wait on AdminClient.createTopics KafkaFuture result 等待AdminClient.createTopics KafkaFuture结果
  3. immediately send a new message to newly created topic (usually the time between operation 2 and 3 is about 200 milliseconds). 立即向新创建的主题发送新消息(通常,操作2和3之间的时间大约为200毫秒)。

My code is as follows: 我的代码如下:

adminClient
  .createTopics(Collections.singleton(new NewTopic(targetTopic, 1, (short) 1)))
  .values()
  .get(targetTopic)
  .get();
producer.send(new ProducerRecord<>(targetTopic, data));

From time to time producer doesn't see the created topic and throws following exception: 生产者有时会看不到创建的主题,并抛出以下异常:

[Producer clientId=producer-1] Error while fetching metadata with correlation id 5 : {targetTopic=UNKNOWN_TOPIC_OR_PARTITION} [Producer clientId = producer-1]提取关联ID为5的元数据时出错:{targetTopic = UNKNOWN_TOPIC_OR_PARTITION}

[Producer clientId=producer-1] Received unknown topic or partition error in produce request on partition targetTopic. [Producer clientId = producer-1]在分区targetTopic上的生产请求中收到未知主题或分区错误。 The topic/partition may not exist or the user may not have Describe access to it 主题/分区可能不存在,或者用户可能没有“描述”权限

This issue is very rare (< 0,1% all created topics). 此问题非常少见(所有已创建主题的<0.1%)。

Is it guaranteed that when AdminClient.createTopics Kafka future is completed then topic is created and Kafka producer should see that topic ? 是否可以保证当AdminClient.createTopics Kafka future完成时可以创建主题,并且Kafka生产者应该看到该主题? If not then which method of topic creation can give me such guarantee ? 如果不是,那么哪种主题创建方法可以给我这样的保证?

I am using kafka-clients:2.0.0 and Kafka HD service on Azure. 我在Azure上使用kafka-clients:2.0.0和Kafka HD服务。 My cluster consists of 3 Zookeeper and 3 Kafka nodes. 我的集群由3个Zookeeper和3个Kafka节点组成。

Kafka client does not guarenteed about atomic topic creation. Kafka客户端不保证原子主题的创建。 You can read it from this documentation . 您可以从本文档中阅读它。 When you create a topic kafka will notify distributed systems about topics information so the action is running on different machines and these can't be atomic without distributed transactional management. 当您创建主题时,kafka会通知分布式系统有关主题的信息,因此操作将在不同的机器上运行,如果没有分布式事务管理,这些动作就不可能实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM