Skip to Content
Kafka权威指南
book

Kafka权威指南

by Neha Narkhede, Gwen Shapira, Todd Palino
January 2018
Beginner to intermediate
234 pages
7h 8m
Chinese
Posts & Telecom Press
Content preview from Kafka权威指南
Kafka
消费者——从
Kafka
读取数据
51
主题T1
分区0
分区1
分区2
分区3
消费者群组1
消费者群组2
消费者1
消费者2
消费者1
消费者2
消费者3
消费者4
4-5:两个消费者群组对应一个主题
4.1.2
 消费者群组和分区再均衡
我们已经从上一个小节了解到,群组里的消费者共同读取主题的分区。一个新的消费者加
入群组时,它读取的是原本由其他消费者读取的消息。当一个消费者被关闭或发生崩溃
时,它就离开群组,原本由它读取的分区将由群组里的其他消费者来读取。在主题发生变
化时,比如管理员添加了新的分区,会发生分区重分配。
分区的所有权从一个消费者转移到另一个消费者,这样的行为被称为
再均衡
。再均衡非常
重要,它为消费者群组带来了高可用性和伸缩性(我们可以放心地添加或移除消费者),
不过在正常情况下,我们并不希望发生这样的行为。在再均衡期间,消费者无法读取消
息,造成整个群组一小段时间的不可用。另外,当分区被重新分配给另一个消费者时,消
费者当前的读取状态会丢失,它有可能还需要去刷新缓存,在它重新恢复状态之前会拖慢
应用程序。我们将在本章讨论如何进行安全的再均衡,以及如何避免不必要的再均衡。
消费者通过向被指派为
群组协调器
broker
(不同的群组可以有不同的协调器)发送
心跳
来维持它们和群组的从属关系以及它们对分区的所有权关系。只要消费者以正常的时间
间隔发送心跳,就被认为是活跃的,说明它还在读取分区里的消息。消费者会在轮询消息
(为了获取消息)或提交偏移量时发送心跳。如果消费者停止发送心跳的时间足够长,会
话就会过期,群组协调器认为它已经死亡,就会触发一次再均衡。 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

精通機器學習

精通機器學習

Aurélien Géron
精通特征工程

精通特征工程

Alice Zheng, Amanda Casari
高效能PYTHON程式設計

高效能PYTHON程式設計

Micha Gorelick, Ian Ozsvald

Publisher Resources

ISBN: 9787115473271