Skip to Content
Kafka权威指南(第2版)
book

Kafka权威指南(第2版)

by Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty
November 2022
Beginner to intermediate
346 pages
11h
Chinese
Posts & Telecom Press
Content preview from Kafka权威指南(第2版)
精确一次性语义
145
➋
消费者不提交自己的偏移量——生产者会将偏移量提交作为事务的一部分,所以需要禁
用自动提交。
➌
在这个例子中,消费者会从输入主题读取数据。假设输入主题中的消息是由事务性生产
者写入的(只是为了好玩儿,实际上我们对输入没有硬性要求)。为了干净地读取事务
(忽略执行中和已中止的事务),可以将消费者隔离级别设置为
read_committed
。需要注
意的是,除了读取已提交的事务,消费者也会读取非事务性的写入。
➍
事务性生产者要做的第一件事是初始化,包括注册事务
ID
和增加
epoch
的值(确保其
他具有相同
ID
的生产者将被视为“僵尸”
,并中止具有相同事务
ID
的旧事务)。
➎
这里使用了消费者订阅
API
,分配给应用程序实例的分区可以在触发再均衡时发生变更。
Kafka 2.5
KIP-447
API
变更是在这个版本中引入的)之前这么做有一定的困难
事务性生产者需要被固定分配到一组分区,因为事务隔离机制要求相同分区对应的事务
ID
必须相同
。(如果事务
ID
发生变化,则“僵尸”隔离保护机制将失效。)
KIP-447
加入了新
API
(已在这个例子中使用)
,将消费者群组信息附加到了事务中,用于实现
“僵尸”隔离。在使用这个方法时,如果相关分区被撤销,则事务也需要被提交。
➏
我们读取了记录,现在要处理它们并生成结果。这个方法可以保证从调用它开始,一直
到事务被提交或被中止,生成的所有内容都是事务的一部分。
➐
在这里处理消息——所有的业务逻辑都在这里。
➑
之前已经提到过,需要将偏移量提交作为事务的一部分,这样可以保证如果生成结果失 ...
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

时间序列分析实战:基于机器学习和统计学

时间序列分析实战:基于机器学习和统计学

Aileen Nielsen
Spark机器学习实战

Spark机器学习实战

Posts & Telecom Press, Siamak Amirghodsi, Meenakshi Rajendran, Broderick Hall, Shuen Mei
写给系统管理员的Python脚本编程指南

写给系统管理员的Python脚本编程指南

Posts & Telecom Press, Ganesh Sanjiv Naik
Kubernetes编程

Kubernetes编程

Michael Hausenblas, Stefan Schimanski

Publisher Resources

ISBN: 9787115601421