使用者组成员没有分区

col17t5w  于 2021-06-07  发布在  Kafka
关注(0)|答案(4)|浏览(419)

我在同一个消费群上启动了两个消费者,我订阅了20个主题(每个主题只有一个分区)
仅用于消费者:
kafka消费群体--引导服务器xx:9092 --group foo—描述—成员—详细

Note: This will not show information about old Zookeeper-based consumers.

CONSUMER-ID                                  HOST            CLIENT-ID       #PARTITIONS     ASSIGNMENT
rdkafka-07cbd673-6a16-4d55-9625-7f0925866540 /xxxxx rdkafka         20              arretsBus(0), capteurMeteo(0), capteurPointMesure(0), chantier(0), coworking(0), horodateur(
0), incident(0), livraison(0), meteo(0), metro(0), parkrelais(0), qair(0), rhdata(0), sensUnique(0), trafic(0), tramway(0), tweets(0), voieRapide(0), zone30(0), zoneRencontre(0)
rdkafka-9a543197-6c97-4213-bd59-cb5a48e4ec15 /xxxx    rdkafka         0

我做错了什么?

w1e3prcc

w1e3prcc1#

好吧,我发现了问题,是因为:
'partition.assignment.strategy':'roundrobin'

CONSUMER-ID                                  HOST            CLIENT-ID       #PARTITIONS     ASSIGNMENT
rdkafka-fa7ec1ca-1c34-498b-bd22-24ad6ca99645 /XXXX  rdkafka         10              capteurPointMesure(0), meteo(0), metro(0), parkrelais(0), qair(0), sensUnique(0), tweets(0),
 voieRapide(0), zone30(0), zoneRencontre(0)
rdkafka-89f765b6-2014-4b8c-bef2-c6406763118b /XXXX    rdkafka         10              arretsBus(0), capteurMeteo(0), chantier(0), coworking(0), horodateur(0), incident(0), livrai
son(0), rhdata(0), trafic(0), tramway(0)

每个主题的范围策略工作,与循环我有预期的结果。

0lvr5msh

0lvr5msh2#

好吧,我读了一些关于这种行为的文章,很有意思的是知道为什么会这样。Kafka的分区分配策略有两种。
范围: Assigns to each consumer a consecutive subset of partitions from each topic it subscribes to. So if consumers C1 and C2 are subscribed to two topics, T1 and T2, and each of the topics has three partitions, then C1 will be assigned partitions 0 and 1 from topics T1 and T2, while C2 will be assigned partition 2 from those topics. Because each topic has an uneven number of partitions and the assignment is done for each topic independently, the first consumer ends up with more partitions than the second. This happens whenever Range assignment is used and the number of consumers does not divide the number of partitions in each topic neatly. 循环: Takes all the partitions from all subscribed topics and assigns them to consumers sequentially, one by one. If C1 and C2 described previously used RoundRobin assignment, C1 would have partitions 0 and 2 from topic T1 and partition 1 from topic T2. C2 would have partition 1 from topic T1 and partitions 0 and 2 from topic T2. In general, if all consumers are subscribed to the same topics (a very common scenario), RoundRobin assignment will end up with all consumers having the same number of partitions (or at most 1 partition difference). 默认策略是range,这解释了为什么会看到这样的分区分布。
所以,我做了一个小实验。我创建了两个控制台消费者,每个人都在听主题 test1, test2, test3, test4 每个主题只有一个分区。正如预期的那样,consumer-1被分配了所有分区。
然后我将分区策略改为 org.apache.kafka.clients.consumer.RoundRobinAssignor 并将其传递给两个控制台使用者,瞧,这两个使用者现在各得到2个分区。
更新:哎呀,没看到几分钟前已经有人回复了。

rbpvctlc

rbpvctlc3#

在apachekafka中,分区号定义了在同一消费者组中消费者的并行级别;这意味着作为同一消费者组的一部分的两个消费者不能从同一分区读取数据。在您的例子中,只有一个分区的主题将被分配给一个使用者,而另一个将空闲等待重新平衡:这意味着如果第一个使用者断开连接,第二个将从空闲移动到使用分区。如果您的期望是为每个消费者获得10个主题,那么这与apachekafka的工作方式无关。正如我所说的,并行单元是主题中的分区,而不是主题本身。

zu0ti5jz

zu0ti5jz4#

在kafka中,一个主题/分区最多只能由一个消费者组中的一个消费者使用,以避免消费者之间的竞争。

相关问题