Skip to Content
使用 Python 的架构模式
book

使用 Python 的架构模式

by Harry Percival, Bob Gregory
May 2025
Intermediate to advanced
304 pages
3h 58m
Chinese
O'Reilly Media, Inc.
Content preview from 使用 Python 的架构模式

第二部分:事件驱动架构 事件驱动架构

很抱歉,我很久以前就为这个话题创造了 "物品 "这个词,因为它会让很多人把注意力集中在较次要的想法上。

最重要的理念是 "信息传递"......制造优秀的、可发展的系统,关键在于设计模块如何交流,而不是模块的内部属性和行为应该是什么。

艾伦-凯

编写一个领域模型来管理单个业务流程固然很好,但当我们需要编写多个模型时该怎么办呢?在现实世界中,我们的应用程序位于一个组织中,需要与系统的其他部分交换信息。您可能还记得图 II-1 所示的上下文图。

面对这种需求,许多团队都会选择通过 HTTP API 集成的微服务。但一不小心,最终就会造成最混乱的局面:分布式大泥球。

在第二部分中,我们将展示如何将第一部分中的技术扩展到分布式系统。我们将放大研究如何将许多通过异步消息传递进行交互的小型组件组成一个系统。

我们将看到服务层和工作单元模式如何让我们重新配置应用程序,使其作为异步消息处理器运行,以及事件驱动系统如何帮助我们将聚合体和应用程序相互解耦。

apwp 0102
图 II-1. 但是,所有这些系统究竟如何相互通信呢?

我们将学习以下模式和技巧:

领域活动

触发跨越一致性边界的工作流程。

信息总线

提供从任何终端调用用例的统一方式。

CQRS

在事件驱动架构中,读写分离可避免尴尬的妥协,并能提高性能和可扩展性。

此外,我们还将添加一个依赖注入框架。这与事件驱动架构本身没有任何关系,但却能整理出许多松散的部分。

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

实用 Python 数据整理与数据质量

实用 Python 数据整理与数据质量

Susan E. McGregor
ppk on JavaScript

ppk on JavaScript

Peter-Paul Koch

Publisher Resources

ISBN: 9798341657212