简体   繁体   English

Kafka消费者分发未按预期工作

[英]Kafka Consumer distribution not working as expected

I have Three topics each having three partitions on a cluster of kafka. 我有三个主题,每个主题在kafka群集上具有三个分区。

now, there are total 9 partitions. 现在,共有9个分区。 and when i create 9 consumers... the 6 are being idle. 当我创建9个消费者时... 6个处于闲置状态。 only three consumers are being used. 仅使用了三个消费者。

the expectation is: each consumer should pickup one partitions and hence, 9 consumer should pick up documents from 9 partitions 预期是:每个使用者应拾取一个分区,因此9个使用者应从9个分区拾取文档

but what happens is: one consumer picks up messages from three paritions one of different topic. 但是发生的事情是:一个消费者从三个主题中选择一个主题不同的消息。

eg i have three topics Topic_A,Topic_B and Topic_C and three partitions each. 例如,我有三个主题Topic_A,Topic_B和Topic_C,每个都有三个分区。 hence parititions are as below: 因此,划分如下:

Topic_A_0, Topic_A_1, Topic_A_2, Topic_B_0, Topic_B_1, Topic_B_2, Topic_C_0, Topic_C_1, Topic_C_2 主题_A_0,主题_A_1,主题_A_2,主题_B_0,主题_B_1,主题_B_2,主题_C_0,主题_C_1,主题_C_2

When i create 9 consumers, the distribution works as below: 当我创建9个使用者时,分布如下:

Consumer1: Topic_A_0,Topic_B_0,Topic_C_0 
Consumer2: Topic_A_1,Topic_B_1,Topic_C_1 
Consumer3: Topic_A_2,Topic_B_2,Topic_C_2
Consumer4,Consumer5,Consumer6,Consumer7,Consumer8,Consumer9 are idle

It should be 它应该是

Consumer1: Topic_A_0
Consumer2: Topic_A_1
Consumer3: Topic_A_2

Consumer4: Topic_B_0
Consumer5: Topic_B_1
Consumer6: Topic_B_2

Consumer7: Topic_C_0 
Consumer8: Topic_C_1 
Consumer9: Topic_C_2

Is there any configuration i need to let all 9 consumer pick up messages from 9 unique parititons? 我是否需要进行任何配置,以允许所有9个消费者从9个唯一的parititon中提取消息?

Make sure your all your consumers are subscribing to same set of topics under the same consumer group id. 确保您的所有消费者都在相同的消费者组ID下订阅相同的主题集。 For the list of topics, you can pass a predefined list or a regular expression for consumers to subscribe from. 对于主题列表,您可以传递预定义的列表或正则表达式供使用者订阅。 The consumer-id can be set using group.id property in consumer. 可以使用消费者中的group.id属性来设置消费者ID。

The default partition assignment strategy doesn't work across topics so this is the expected behaviour. 默认的分区分配策略不适用于所有主题,因此这是预期的行为。 A similar question here : Kafka Consumers are balanced across topics 这里有一个类似的问题: 卡夫卡消费者在各个主题之间保持平衡

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

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