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权威指南
流式处理
199
}
}
➊
基于拓扑和配置属性定义一个 KafkaStreams 对象。
➋
启动
Kafka Streams
引擎。
过一段时间后将它停掉。
就是这么简单!本例只用了几行代码,就演示了如何实现
单事件处理
模式(在事件上使用
map
filter
),然后通过
group by
操作对数据进行
重新分区
,并为统计记录个数维护了
一个简单的
本地状态
建议运行完整的示例,
GitHub
库的
README
文件包含了如何运行示例的说明。
也许你会注意到,除了
Kafka
外,不需要在机器上安装任何软件,就可以运行完整的示
例。这类似于在“本地模式”下使用
Spark
。主要的不同之处在于,如果主题包含了多个
分区,就可以运行多个字数统计应用实例(在不同的命令行终端运行),而这也就是第一
Streams
集群。几个字数统计应用实例之间互相交互,协调处理任务。
Spark
的本地模
式非常简单,但要在生产环境运行集群,需要安装
YARN
或者
Mesos
,并在所有的机器上
安装
Spark
,然后将你的应用提交到集群上,所以
Spark
有较高的准入门槛。而如果使用
Streams API
,只需要启动几个应用实例就可以拥有一个集群。在开发机上运行和在生产环
境中运行几乎是一样的。
11.4.2
 股票市场统计
接下来的这个例子会复杂一些,下面将从一个股票交易事件流里读取事件,这些事件包含
了股票代码、沽盘价和要价规模。在股票交易里,沽盘价是指卖方的出价,买入价是指买
方建议支付的价格,要价规模是指卖方愿意在相应价格基础上出售的股数。为了简单起 ...
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