Skip to Content
构建事件驱动的数据网格
book

构建事件驱动的数据网格

by Adam Bellemare
May 2025
Beginner to intermediate
262 pages
2h 53m
Chinese
O'Reilly Media, Inc.
Content preview from 构建事件驱动的数据网格

第 6 章 事件模式 事件模式

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

定义明确的模式对任何数据产品都至关重要。对于事件而言,模式包括对字段名称、类型、默认值和边界的明确声明,为人类和机器提供清晰的数据内容。模式为数据产品生产者和消费者提供了清晰的数据共识。模式可消除歧义,支持发现和自助服务,并降低使用数据者误解数据的风险。

模式简化了数据发现和自助服务。您可以将文档嵌入模式本身,使数据定义和文档保持紧密耦合。代码生成器与模式相结合,可生成适用于用户所选编程语言的类和对象。同样,事件生成器可使用模式生成与定义相匹配的事件,从而为边界条件提供了生成各种测试数据的机制。

模式为随时间演变的数据提供了一个框架,但模式演变的选择取决于技术选择。使用模式演进的主要目的是,随着新业务需求的增加以及领域的变化和扩展,更新和更改数据,而不会对数据产品的消费者造成不必要的影响。

本章对事件驱动数据 Data Mesh 的模式进行了规定性和观点性的探讨。有许多不同的模式技术,也有许多不同的方法通过事件在系统间进行数据通信。但是,有些方法和技术比其他方法和技术更好--它们更常见、更灵活,也反映了大多数企业使用和交流事件的方式。

在深入探讨模式之前,让我们退一步,更好地了解模式与通过数据产品提供重要业务数据的关系。为此,我们需要了解事件是如何创建、序列化并通过网络发送到事件流中存储的。我们还将了解这一过程的反面,即事件从事件流中消费、反序列化并由消费者处理。

序列化和反序列化简介

序列化(Serialization)是将具有明确定义模式的事件对象转换为字节序列的操作。生产者内存中的表示被序列化(转换)为字节序列,以便于通过 Network+ 发送并写入事件流。模式为确保数据能转换成字节序列提供了约束条件。例如,如果模式规定名为length 的字段必须是Integer ,那么当length 设置为String "six feet" 时,尝试序列化时就会出现异常。

图 6-1显示了生产者将生产者语言对象转换成字节序列,然后写入事件流的工作流程。请注意,模式是附加到序列化事件中的,这样消费者就能获得一份副本用于反序列化。我们可以使用一些技巧来消除为每个事件发送模式的需要,本章稍后我们将对此进行探讨。

Producer serializing the event object into bytes and writing it to the event stream
图 6-1. 生产者将事件对象序列化为字节并写入事件流

在事件流的另一端,消费者会逆转这一过程,将字节序列反序列化为对象。图 6-2展示了消费、反序列化和将数据转换为可由消费者业务逻辑代码处理的事件表示的过程。

模式技术是事件驱动型 Data Mesh 的重要组成部分,因为它们是数据产品与其消费者之间契约的基础。

A consumer reading from the event stream and deserializing the bytes back into an event representation
图 6-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

《构建微服务》,第二版

《构建微服务》,第二版

Sam Newman
Peer-to-Peer

Peer-to-Peer

Andy Oram

Publisher Resources

ISBN: 9798341658035