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权威指南
94
6
个账号里有
110
美元”就是幂等的,因为即使多次发送这样的消息,产生的结果都是一样
的。不过消息“往这个账号里增加
10
美元”就不是幂等的。
6.4.3
 额外的错误处理
使用生产者内置的重试机制可以在不造成消息丢失的情况下轻松地处理大部分错误,不过
对于开发人员来说,仍然需要处理其他类型的错误,包括:
不可重试的
broker
错误,例如消息大小错误、认证错误等;
在消息发送之前发生的错误,例如序列化错误;
在生产者达到重试次数上限时或者在消息占用的内存达到上限时发生的错误。
我们在第
3
章讨论了如何为同步发送消息和异步发送消息编写错误处理器。这些错误处理
器的代码逻辑与具体的应用程序及其目标有关。丢弃“不合法的消息”?把错误记录下
来?把这些消息保存在本地磁盘上?回调另一个应用程序?具体使用哪一种逻辑要根据具
体的架构来决定。只要记住,如果错误处理只是为了重试发送消息,那么最好还是使用生
产者内置的重试机制。
6.5
 在可靠的系统里使用消费者
我们已经学习了如何在保证
Kafka
可靠性的前提下生产数据,现在来看看如何在同样的前
提下读取数据。
在本章的开始部分可以看到,只有那些被提交到
Kafka
的数据,也就是那些已经被写入所
有同步副本的数据,对消费者是可用的,这意味着消费者得到的消息已经具备了一致性。
消费者唯一要做的是跟踪哪些消息是已经读取过的,哪些是还没有读取过的。这是在读取
消息时不丢失消息的关键。
在从分区读取数据时,消费者会获取一批事件,检查这批事件里最大的偏移量,然后从这
个偏移量开始读取另外一批事件。这样可以保证消费者总能以正确的顺序获取新数据,不 ...
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