消费者组成员没有分区

时间:2018-08-06 08:31:31

标签: apache-kafka kafka-consumer-api

我在同一个消费者组中启动了两个消费者,我订阅了20个主题(每个主题只有一个分区)

仅在消费者上使用:

  

kafka-consumer-groups --bootstrap-server XXXXX:9092 --group foo   --describe --members --verbose

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 

我做错了什么?

4 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

在Apache Kafka中,分区号定义了根据相同使用者组中的使用者所需的并行度。这意味着作为同一使用者组一部分的两个使用者无法从同一分区读取。 在您的情况下,您的主题只有一个分区,该分区将仅分配给一个使用者,另一个分区将处于空闲状态,等待重新平衡:这意味着,如果第一个使用者断开连接,则第二个使用者将从空闲状态转变为消耗状态。划分。 如果您期望每个消费者获得10个主题,那不是Apache Kafka的工作方式。正如我所说的,并行单元是主题中的分区,而不是主题本身。

答案 2 :(得分:1)

好吧,我读了一些关于这种行为的书,知道为什么会发生很有趣。卡夫卡中有两种分区分配策略。

  • 范围: 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.

  • RoundRobin: 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).

默认策略是“范围”,它说明了为什么看到这种分区分布。

所以,我做了一个小实验。我创建了两个控制台使用者,每个使用者都在听主题test1, test2, test3, test4,并且每个主题只有一个分区。如预期的那样,消费者1被分配了所有分区。

然后,我将分区策略更改为org.apache.kafka.clients.consumer.RoundRobinAssignor并将其传递给控制台用户和voila,两个消费者现在每个都获得2个分区。

更新: 糟糕,几分钟前还没有收到答复。

答案 3 :(得分:0)

好的,我发现了问题所在,它可以与:

'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)

每个主题的范围策略工作,与轮循机制一起使用,可获得预期结果。

相关问题