当前位置:网站首页>第5章 消费者组详解
第5章 消费者组详解
2022-07-06 09:29:00 【留不住斜阳】
5.1 消费者组概念
什么是consumer group?
consumer group是kafka提供的可扩展且具有容错性的消费者机制。既然是一个组,那么组内必然可以有多个消费者或消费者实例(consumer instance),它们共享一个公共的ID,即group ID。组内的所有消费者协调在一起来消费订阅的主题(subscribed topics)的所有分区(partition)。每个分区只能由同一个消费组内的一个consumer来消费。
consumer group三个特征
- consumer group可以有一个或多个consumer instance,consumer instance可以是一个进程,也可以是一个线程
- group.id是一个字符串,唯一标识一个consumer group
- consumer group订阅的topic的每个分区只能分配给某个group下的一个consumer(当然该分区还可以被分配给其他group)
5.2 消费者位置
消费者在消费的过程中需要记录自己消费了多少数据,即消费位置信息。在Kafka中这个位置信息有个专门的术语:位移(offset)。很多消息引擎都把这部分信息保存在服务器端(broker端)。这样做的好处是实现简单,但会有三个主要的问题:
- broker从此变成有状态的,会影响伸缩性;
- 需要引入应答机制(acknowledgement)来确认消费成功。
- 由于要保存很多consumer的offset信息,必然引入复杂的数据结构,造成资源浪费。
而Kafka选择了不同的方式,每个consumer group保存自己的位移信息,那么只需要一个整数表示位置就够了;同时可以引入checkpoint机制定期持久化,简化了应答机制的实现。
5.3 位移管理
5.3.1 自动VS手动
Kafka默认定期自动提交位移(enable.auto.commit = true),当然可以选择手动提交位移实现。另外kafka会定期把group消费情况保存起来,做成一个offset map,如下图所示
5.3.2 位移提交
老版本的位移是提交到zookeeper中,目录结构是/consumers/<group.id>/offsets/<topic>/<partitionId>,但是zookeeper其实并不适合进行大批量的读写操作,尤其是写操作。因此kafka提供了另一种解决方案:增加__consumer_offsets topic,将offset信息写入这个topic,摆脱对zookeeper的依赖(指保存offset这件事情)。__consumer_offsets中的消息保存了每个consumer group某一时刻提交的offset信息。依然以上图中的consumer group为例,格式大概如下
边栏推荐
- Study notes of Tutu - process
- Generate random password / verification code
- (POJ - 3258) River hopper (two points)
- Problem - 1646C. Factorials and Powers of Two - Codeforces
- Click QT button to switch qlineedit focus (including code)
- Oneforall installation and use
- Market trend report, technological innovation and market forecast of double door and multi door refrigerators in China
- 875. Leetcode, a banana lover
- QT实现圆角窗口
- Specify the format time, and fill in zero before the month and days
猜你喜欢

Codeforces Round #797 (Div. 3)无F

去掉input聚焦时的边框

sublime text 代码格式化操作

QT style settings of qcobobox controls (rounded corners, drop-down boxes, up expansion, editable, internal layout, etc.)

(POJ - 3685) matrix (two sets and two parts)

Problem - 922D、Robot Vacuum Cleaner - Codeforces

QWidget代码设置样式表探讨

使用jq实现全选 反选 和全不选-冯浩的博客

Suffix expression (greed + thinking)

Li Kou: the 81st biweekly match
随机推荐
解决Intel12代酷睿CPU单线程调度问题(二)
Read and save zarr files
807. Maintain the urban skyline
The "sneaky" new asteroid will pass the earth safely this week: how to watch it
(lightoj - 1349) Aladdin and the optimal invitation (greed)
SF smart logistics Campus Technology Challenge (no T4)
Installation and configuration of MariaDB
Configuration du cadre flask loguru log Library
QT implementation fillet window
(lightoj - 1323) billiard balls (thinking)
Summary of FTP function implemented by qnetworkaccessmanager
Research Report on market supply and demand and strategy of double drum magnetic separator industry in China
Codeforces round 797 (Div. 3) no f
300th weekly match - leetcode
Spark的RDD(弹性分布式数据集)返回大结果集
Market trend report, technical innovation and market forecast of double-sided foam tape in China
AcWing:第58场周赛
Local visualization tools are connected to redis of Alibaba cloud CentOS server
Flask框架配置loguru日志库
Codeforces Round #803 (Div. 2)A~C