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

精通機器學習

精通機器學習

Aurélien Géron
精通特征工程

精通特征工程

Alice Zheng, Amanda Casari
高效能PYTHON程式設計

高效能PYTHON程式設計

Micha Gorelick, Ian Ozsvald

Publisher Resources

ISBN: 9787115473271