Kafka 重新平衡旨在将主题的所有分区重新分配给订阅者组的活跃成员,以便任何主题分区在任何给定时刻仅由一个消费者使用。因此,如果消费者刚刚订阅了一个主题,一切都清楚了,但是消费者 api 还提供了一种将特定分区分配给消费者的方法:
void assign(Collection<TopicPartition> partitions)
现在假设我们有:
- 具有 5 个分区的主题:1、2、3、4、5
- 拥有 3 名成员的消费者组:1,2,3
- 成员 1 和 2 刚刚订阅某个主题,成员 3 已将分区 1 分配给自己
那么在这种情况下重新平衡将如何进行?分区 1 是否总是分配给成员 3(当它还活着时),导致其他成员只能从其他分区(2,3,4,5)读取?组协调员是否可以为成员 3 分配另一个分区?如果成员 3 出现故障然后又回来,分区 1 会发生什么情况?
提前致谢
最佳答案
在kafka文档中找到:
public void assign(Collection<TopicPartition> partitions)
Manual topic assignment through this method does not use the consumer's group management functionality. As such, there will be no rebalance operation triggered when group membership or cluster and topic metadata change. Note that it is not possible to use both manual partition assignment with assign(Collection) and group assignment with subscribe(Collection, ConsumerRebalanceListener).
因此组中的所有消费者都应该使用手动分区分配或仅订阅(获取分区的动态分配)。
关于java - 当组中的一个订阅者被严格分配到特定分区时,Kafka 重新平衡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42831972/