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权威指南
Kafka
生产者——向
Kafka
写入数据
41
@Override
public void close() {
// 不需要关闭任何东西
}
}
只要使用这个 CustomerSerializer,就可以把消息记录定义成 ProducerRecord<String,
Customer>,并且可以直接把 Customer 对象传给生产者。这个例子很简单,不过代码看起
来太脆弱了——如果我们有多种类型的消费者,可能需要把
customerID
字段变成长整型,
或者为
Customer
添加
startDate
字段,这样就会出现新旧消息的兼容性问题。在不同版
本的序列化器和反序列化器之间调试兼容性问题着实是个挑战——你需要比较原始的字节
数组。更糟糕的是,如果同一个公司的不同团队都需要往
Kafka
写入
Customer
数据,那
么他们就需要使用相同的序列化器,如果序列化器发生改动,他们几乎要在同一时间修改
代码。
基于以上几点原因,我们不建议使用自定义序列化器,而是使用已有的序列化器和反序列
化器,比如
JSON
Avro
Thrift
Protobuf
。下面我们将会介绍
Avro
,然后演示如何序列
Avro
记录并发送给
Kafka
3.5.2
 使用
Avro
序列化
Apache Avro
(以下简称
Avro
)是一种与编程语言无关的序列化格式。
Doug Cutting
创建了
这个项目,目的是提供一种共享数据文件的方式。
Avro
数据通过与语言无关的
schema
来定义。
schema
通过
JSON
来描述,数据被序列化
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