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版)
302
14
除了单元测试,还需要进行集成测试。对
Streams
来说,有两个流行的集成测试框架:
EmbeddedKafkaCluster
Testcontainers
。前者的
broker
和测试代码运行在同一个
JVM
中,
后者的
broker
运行
Docker
容器中
(还有其他需要用到的组件)。建议使用
Testcontainer
因为它使用了
Docker
可以将
Kafka
、依赖项和要用到的资源与要测试的应用程序完全隔
离开。
以上这些只是对
Streams
测试方法的一个简单概述
。如果想更深入地了解拓扑测试,并获
得更详细的代码示例,那么建议阅读“
T
esting Kafka Streams
A Deep Dive
”这篇博文。
14.5.4
 扩展拓扑
Streams
的伸缩方式有两种,一种是在一个应用程序实例中运行多个线程,一种是在分
布式实例之间进行负载均衡。我们可以在一台机器上使用多线程或在多台机器上运行
Streams
应用程序
,不管是哪一种,应用程序中的所有活动线程都将均衡地分摊数据处理
工作。
Streams
引擎会将拓扑分为多个并行执行的任务
。任务数由
Streams
引擎决定,也取决于应
用程序处理的主题有多少个分区。每个任务负责处理一部分分区:它们会订阅这些分区并
从分区中读取事件。对于所读取的每一个事件,任务都会在将最终结果写入目标主题之前
按顺序执行所有的处理步骤。这些任务是
Streams
最基本的并行执行单元
,每个任务都可
以独立执行,如图
14-1
1
所示。
主题
输出主题
分区
1
任务
1
任务
2
分区
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

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

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

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