多个Kafka使用者可以从分区读取相同的消息吗 [英] Can multiple Kafka consumers read same message from the partition

查看:611
本文介绍了多个Kafka使用者可以从分区读取相同的消息吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正计划编写一个Kafka使用者(java),该使用者读取Kafka队列以执行消息中的操作.

We are planning to write a Kafka consumer(java) which reads Kafka queue to perform an action which is in the message.

由于使用者独立运行,因此消息一次只能由一位使用者处理吗?其他所有使用者都处理相同的消息,因为他们在分区中有自己的偏移量.

As the consumers run independently, will the message is processed by only one consumer at a time? Else all the consumers process the same message as they have their own offset in the partition.

请帮助我理解.

推荐答案

这取决于

It depends on Group ID. Suppose you have a topic with 12 partitions. If you have 2 Kafka consumers with the same Group Id, they will both read 6 partitions, meaning they will read different set of partitions = different set of messages. If you have 4 Kafka cosnumers with the same Group Id, each of them will all read three different partitions etc.

但是,当您设置不同的组ID时,情况就会改变.如果您有两个具有不同组ID的Kafka使用者,则他们将读取所有12个分区,而彼此之间没有任何干扰.这意味着两个使用者将独立地阅读完全相同的消息集.如果您有四个具有不同组ID的Kafka使用者,他们将全部读取所有分区,等等.

But when you set different Group Id, the situation changes. If you have two Kafka consumers with different Group Id they will read all 12 partitions without any interference between each other. Meaning both consumers will read the exact same set of messages independently. If you have four Kafka consumers with different Group Id they will all read all partitions etc.

这篇关于多个Kafka使用者可以从分区读取相同的消息吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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