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版)
流式处理
285
与表不同,流包含了历史变更数据。
是一系列事件,每个事件就是一个变更。表表示的
是世界的当前状态,是发生多个变更后的结果。可见,表和流是同一枚硬币的两面——世
界总是在发生变化,我们有时候对导致发生变化的事件感兴趣,有时候对世界的当前状态
感兴趣。如果一个系统允许通过这两种方式来看待数据,那么它就比只支持一种方式的系
统更强大。
要将表转化成流,需要捕获所有对表做出的变更。要将
insert
事件、
update
事件和
delete
事件保存到流里。大多数数据库提供了
CDC
解决方案,有很多
Kafka
连接器可以
将这些变更发送到
Kafka
,用于后续的流式处理。
要将流转化成表,需要应用流里所有的变更。这也叫作流的
物化
。我们需要在内存、内部
状态存储或外部数据库中创建一张表,然后从头到尾遍历流里所有的事件,逐个修改状
态。在完成这个过程之后,就得到了一张表,它代表了某个时间点的状态。
假设我们有一家鞋店,店里的零售活动可以用一个事件流来表示。
“红色鞋子、蓝色鞋子和绿色鞋子到货。”
“蓝色鞋子卖出。”
“红色鞋子卖出。”
“蓝色鞋子退货。”
“绿色鞋子卖出。”
如果想知道现在仓库里还有哪些库存或到目前为止赚了多少钱,就需要对视图进行物化。
从图
14-1
可以看出
,我们目前还有
299
双红色鞋子。如果想知道鞋店的繁忙程度,那么可
以查看整个事件流,可以看到总共发生了
4
个顾客事件
。我们可能还想知道为什么蓝色鞋
子被退货了。
库存变更事件流
发货销售销售 退货
代表库存最新状态的
表或物化视图
蓝色鞋子
红色鞋子
绿色鞋子 ...
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