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权威指南
可靠的数据传递
95
我们在第
4
章已经详细介绍了消费者
API
的使用,还介绍了多种提交偏移量的方式。下面
会介绍一些关键的注意事项,如果要了解消费者
API
的使用细节,请参考第
4
章。
6.5.1
 消费者的可靠性配置
为了保证消费者行为的可靠性,需要注意以下
4
个非常重要的配置参数。
1
个是
group.id。这个参数在第
4
章已经详细解释过了,如果两个消费者具有相同的
group.id,并且订阅了同一个主题,那么每个消费者会分到主题分区的一个子集,也就是
说它们只能读到所有消息的一个子集(不过群组会读取主题所有的消息)。如果你希望消
费者可以看到主题的所有消息,那么需要为它们设置唯一的 group.id
2
个是 auto.offset.reset。这个参数指定了在没有偏移量可提交时(比如消费者第
1
启动时)或者请求的偏移量在
broker
上不存在时(第
4
章已经解释过这种场景),消费者
会做些什么。这个参数有两种配置。一种是 earliest,如果选择了这种配置,消费者会
从分区的开始位置读取数据,不管偏移量是否有效,这样会导致消费者读取大量的重复数
据,但可以保证最少的数据丢失。一种是 latest,如果选择了这种配置,消费者会从分区
的末尾开始读取数据,这样可以减少重复处理消息,但很有可能会错过一些消息。
3
个是 enable.auto.commit。这是一个非常重要的配置参数,你可以让消费者基于任务
调度自动提交偏移量,也可以在代码里手动提交偏移量。自动提交的一个最大好处是,在
实现消费者逻辑时可以少考虑一些问题。如果你在消费者轮询操作里处理所有的数据,那 ...
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