Kafka:使用通用消费者组访问多个主题 [英] Kafka : Use common consumer group to access multiple topics

查看:37
本文介绍了Kafka:使用通用消费者组访问多个主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的集群运行 Kafka 0.11,并且对使用消费者组有严格的限制.我们不能使用任意的消费者组,因此管理员必须创建所需的消费者组.

Our cluster runs Kafka 0.11 and has strict restrictions on using consumer groups. We cannot use arbitrary consumer groups so Admin has to create required consumer groups.

我们运行 Kafka Connect HDFS Sink 从主题读取数据并写入 HDFS.所有主题只有一个分区.

We run Kafka Connect HDFS Sinks to read data from topics and write to HDFS. All the topics have only one partition.

在 Kafka HDFS Sink 中使用消费者组时,我可以考虑以下两种模式.

I can consider following two patterns when using Consumer Groups in Kafka HDFS Sink.

如图所示:

案例 1:每个主题都有自己的消费者组

Case 1: Each topic has its own Consumer Group

案例 2:所有主题都有一个共同的消费者组

Case 2: All the topics have a common Consumer Group

我知道当一个主题有多个分区时,如果一个消费者失败,同一消费者组中的另一个消费者会接管该分区.

I am aware that when a topic has multiple partitions, and if a consumer failed, another consumer in the same consumer group take over that partition.

我的问题:

当多个主题共享同一个消费群体时,是否会发生同样的事情?即:如果一个消费者失败(HDFS 接收器),另一个消费者(HDFS 接收器连接器)是否会接管工作并读取该主题?

Does the same thing happen when multiple topics share the same consumer group? ie: if a Consumer failed(HDFS Sink), will another Consumer(HDFS Sink connector) takeover the work and read from that topic?

更新:每个 Kafka HDFS Sink Connector 仅订阅一个主题.

Update: Each Kafka HDFS Sink Connector subscribed to only one topic.

推荐答案

我很惊讶所有是"的答案都是错误的.我刚刚测试了它,并且对于 不同 主题的消费者使用相同的 group.id 效果很好,并不意味着他们共享消息,因为对于 Kafka 来说,关键是 (topic, group) 而不仅仅是 (group).这是我所做的:

I'm surprised that all answers with "yes" are wrong. I just tested it and having the same group.id for consumers for different topic works well and does NOT mean that they share messages, because for Kafka the key is (topic, group) rather than just (group). Here is what I did:

  1. 创建了 2 个不同的主题 T1 和 T2,每个主题有 2 个分区
  2. 创建了2个同组的消费者xxx
  3. 将消费者 C1 分配给 T1,将消费者 C2 分配给 T2
  4. 向 T1 生成消息 - 只有分配给 T1 的消费者 C1 处理它们
  5. 向 T2 生成消息 - 只有分配给 T2 的消费者 C2 处理它们
  6. 杀死消费者 C1 并重复 4-5 步.只有消费者 C2 处理来自 T2 的消息
  7. 来自 T1 的消息未被处理

结论:订阅不同主题的同组名消费者不会消费其他主题的消息,因为key是(topic, group)

Conclusion: Consumers with the same group name subscribed to different topics will NOT consume messages from other topics, because the key is (topic, group)

这篇关于Kafka:使用通用消费者组访问多个主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆