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版)
Kafka
生产者——向
Kafka
写入数据
35
3.1
 生产者概览
一个应用程序会在很多情况下向
Kafka
写入消息:记录用户的活动(用于审计和分析)、
记录指标、记录日志、记录从智能家电收集到的信息、与其他应用程序进行异步通信、缓
冲即将写入数据库的数据,等等。
多样的应用场景意味着多样的需求:是否每条消息都很重要?是否允许丢失一小部分消
息?是否可以接受偶尔出现重复消息?是否有严格的延迟和吞吐量需求?
之前提到的信用卡事务处理系统不允许消息丢失或重复,可接受的最高延迟为
500
秒,
对吞吐量要求较高——我们希望每秒可以处理
100
万条消息。
另一种应用场景是保存网站的点击信息。在这个场景中,允许丢失少量消息或出现少量重
复消息,延迟可以高一些,只要不影响用户体验就行。换句话说,只要保证用户点击链接
后可以马上加载页面,我们并不介意消息需要在几秒之后才能到达
Kafka
服务器
。吞吐量
则取决于用户在网站上的活跃度。
不同的应用场景直接影响如何使用和配置生产者
API
尽管生产者
API
使用起来很简单
,但消息的发送过程还是有点儿复杂。图
3-1
展示了向
Kafka
发送消息的主要步骤。
主题 A
分区 0
主题 B
分区 1
批次 0
批次 1
批次 2
批次 0
批次 1
批次 2
分区器
序列化器
重试?
失败?
如果成功,
就返回元数据
如果不能重试,
就抛出异常
Kafka broker
3-1Kafka 生产者组件图
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