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版)
85
5
编程式管理
Kafka
虽然现在已经有很多基于命令行或图形界面的
Kafka
管理工具(第
9
章将介绍它们),但
有时候你可能想直接在客户端应用程序中执行一些管理命令。基于用户的输入或数据创建
新主题就是一个非常常见的场景:物联网应用程序从用户设备接收事件,并根据设备类型
将事件写入不同的主题。如果制造商生产了一种新设备,那么你要么为其手动创建一个新
主题,要么让应用程序在接收到包含未识别类型设备的事件时动态创建一个新主题。虽然
后一种方式有缺点,但在一些应用场景中,不依赖于额外的处理过程来生成主题是一种很
有吸引力的解决方案。
Kafka
0.1
1
版本中加入了
AdminClient
,为之前只能通过命令行完成的管理功能提供了编
API
:查看、创建和删除主题,描述集群,管理
ACL
和修改配置。
假设你的应用程序要为某个主题生成事件,在生成第一个事件之前,这个主题必须存在。
Kafka
加入
AdminClient
之前
,我们只有很少的选择,并且没有一个是特别友好的:可
以捕获
producer.send()
方法的
UNKNOWN_TOPIC_OR_PARTITION
异常,让用户知道需要先创
建主题,或者寄希望于
Kafka
群启用了自动创建主题功能,或者依赖
Kafka
的内部
API
并接受没有兼容性保证的后果。现在,
Kafka
提供了
AdminClient
,我们就有了一种更好的
解决方案:用
AdminClient
检查主题是否存在,如果不存在,就当场创建。
本章将先对
AdminClient
行概览,然后再深入探讨如何在应用程序中使用它。我们将重 ...
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