当前位置:网站首页>第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为例,格式大概如下
边栏推荐
- Market trend report, technical innovation and market forecast of China's desktop capacitance meter
- 生成随机密码/验证码
- 指定格式时间,月份天数前补零
- Research Report on market supply and demand and strategy of double drum magnetic separator industry in China
- Bidirectional linked list - all operations
- AcWing:第56场周赛
- QT实现窗口置顶、置顶状态切换、多窗口置顶优先关系
- Research Report on market supply and demand and strategy of China's four seasons tent industry
- Tree of life (tree DP)
- input 只能输入数字,限定输入
猜你喜欢

sublime text 代码格式化操作

Advancedinstaller安装包自定义操作打开文件

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

Log statistics (double pointer)

Remove the border when input is focused

Some problems encountered in installing pytorch in windows11 CONDA

Codeforces Round #801 (Div. 2)A~C

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

Pull branch failed, fatal: 'origin/xxx' is not a commit and a branch 'xxx' cannot be created from it

软通乐学-js求字符串中字符串当中那个字符出现的次数多 -冯浩的博客
随机推荐
生成随机密码/验证码
去掉input聚焦时的边框
QT实现窗口渐变消失QPropertyAnimation+进度条
<li>圆点样式 list-style-type
1529. Minimum number of suffix flips
Codeforces Round #802(Div. 2)A~D
Install Jupiter notebook under Anaconda
useEffect,函数组件挂载和卸载时触发
Share an example of running dash application in raspberry pie.
拉取分支失败,fatal: ‘origin/xxx‘ is not a commit and a branch ‘xxx‘ cannot be created from it
日期加1天
(lightoj - 1369) answering queries (thinking)
Tert butyl hydroquinone (TBHQ) Industry Research Report - market status analysis and development prospect forecast
Codeforces Round #799 (Div. 4)A~H
AcWing:第56场周赛
js时间函数大全 详细的讲解 -----阿浩博客
Raspberry pie 4B installation opencv3.4.0
Market trend report, technological innovation and market forecast of double door and multi door refrigerators in China
Market trend report, technical innovation and market forecast of China's desktop capacitance meter
Pull branch failed, fatal: 'origin/xxx' is not a commit and a branch 'xxx' cannot be created from it