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权威指南
流式处理
197
能需要清理之前的输出流。虽然
Streams
提供了一个工具用于重置应用的状态,不过如果
有条件运行两个应用程序并生成两个结果流,还是建议使用第一种方案。第一种方案更加
安全,多个版本可以来回切换,可以比较不同版本的结果,而且不会造成数据的丢失,也
不会在清理过程中引入错误。
11.4
 
Streams
示例
为了演示如何在实际中实现这些模式,下面将给出一些使用
Streams API
的例子。之所以
使用这个
API
,是因为它相对简单,而且它是与
Kafka
一起发布的,用户可以直接使用它。
不过要记住一点,我们可以使用任意的流式处理框架和软件包来实现这些模式,这些模式
具有通用性。
Kafka
有两个基于流的
API
,一个是底层的
Processor API
,一个是高级的
Streams DSL
。下
面的例子中将使用
Streams DSL
。通过为事件流定义转换链可以实现流式处理。转换可以
是简单的过滤器,也可以是复杂的流与流的连接。我们可以通过底层的
API
实现自己的转
换,不过没必要这么做。
在使用
DSL API
时,一般会先用
StreamBuilder
创建一个
拓扑
topology
)。拓扑是一个有
向图(
DAG
),包含了各个转换过程,将会被应用在流的事件上。在创建好拓扑后,使用
拓扑创建一个 KafkaStreams 执行对象。多个线程会随着 KafkaStreams 对象启动,将拓扑应
用到流的事件上。在关闭 KafkaStreams 对象时,处理也随之结束。
下面将展示一些使用
Streams
来实现上述模式的例子。字数统计这个例子用于演示 ...
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