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权威指南
流式处理
201
参数就是本地状态存储的名字,它可以是任意具有唯一性的名字。
󲣃
聚合结果是一个表,包含了股票信息,并使用时间窗口作为主键、聚合结果作为值。它
表示一条记录,以及从变更流中计算得出的特定状态(参考“概念”一节有关流和表二
元性的讨论)。这里想将表重新转成事件流,不过不再使用整个时间窗口作为键,而是
使用一个包含了股票信息和时间窗口起始时间的对象。
toStream 方法将表转成一个流,
并将键转成 TickerWindow 对象。
󲣄
最后一步是更新平均价格。现在,聚合结果里包含了总价和交易数量。遍历所有的记
录,并使用现有的统计信息计算平均价格,然后把它写到输出流里。
󲣅
最后将结果写到 stockstats-output 流里。
定义好流程之后,用它生成
KafkaStreams
对象,并运行它,就像之前的“字数统计”那个
例子一样。
这个例子展示了如何在一个流上面进行基于时间窗的聚合,这也许就是最为流行的流式处
理使用场景。大家可以发现,为聚合维护一个本地状态是一件多么简单的事情,只需要提
供一个 Serde 对象和状态存储的名字。不仅如此,这个应用还能扩展到多个实例,如果有
实例失效,它的分区将会被分配给其他存活的实例,从而实现自动的故障恢复。在
11.5
将介绍更多有关这种机制的实现原理。
完整的例子和运行说明可以在
GitHub
https://github.com/gwenshap/kafka-streams-stockstats
上找到。
11.4.3
 填充点击事件流
最后一个例子将通过填充网站点击事件流来演示如何进行流的连接 ...
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