0

我在生产者身上看到 org.apache.kafka.common.errors.NotLeaderForPartitionException,据我了解,这是在生产者尝试向不是分区领导者的代理生成消息时发生的。这是否意味着每次领导者完成写入请求时,它首先检查它是否是领导者?如果是,这是否会转化为每个写入请求的 zookeeper 请求,以了解节点是否是领导者?

4

1 回答 1

0

How Producer Get MetaData About Brokers
The producer sends a meta request with a list of topics to one of the brokers you supplied when configuring the producer.

The response from the broker contains a list of partitions in those topics and the leader for each partition. The producer caches this information and therefore, it knows where to redirect the messages.

When Producer Will Refresh MetaData
I think this depends what kafka client you used.There are some small differents between ruby, java or other kafka client.for example, in java:

  1. producer will fetch metadata when client initialize,then period update it depends on expiration time.
  2. producer also will force update metadata when request error occured,such as InvalidMetadataException.

But in ruby-kafka client, it usually refresh metadata when error occured or initialize.

于 2020-08-17T14:03:41.120 回答