Skip to Content
微服务与事件驱动架构
book

微服务与事件驱动架构

by Adam Bellemare
October 2021
Beginner to intermediate
250 pages
7h 11m
Chinese
Posts & Telecom Press
Content preview from 微服务与事件驱动架构
74
6
想重新同步全球不同地区的事件,这是一个需要考虑的因素。
NTP
步也容易出现故障,因为网络中断、配置错误和暂时性问题会阻止实例同步。
NTP
服务器本身也会变得不可靠或无响应。实例中的时钟可能会受到多租户问题的影响,比如
共享底层硬件的基于虚拟机的系统。
对绝大多数业务情况来说,频繁与
NTP
服务器同步可以为系统事件时间提供足够的一致
性。
NTP
服务器和
GPS
使用的改进已经开始将
NTP
同步精度持续提升到亚毫秒级
。用时
间戳赋值的创建时间和摄取时间可以高度一致,尽管少部分乱序问题仍然会发生。本章后
面将介绍迟到事件的处理。
6.2.2
 处理带时间戳的事件
时间戳提供了一种以一致的时间顺序处理分布于多个事件流和分区中的事件的方式。许多
情况要求基于时间来保持事件之间的顺序,并且无论何时处理事件流,都需要一致的、可
重复产生的结果。使用偏移量作为比较方法仅适用于单个事件流分区内的事件,而事件通
常需要从多个不同的事件流中进行处理。
示例
在处理多个分区时选择事件的顺序
银行必须确保以正确的时间顺序处理存款和取款事件流。它对存款和取款进行有状态的实
时统计,当客户的账户余额低于
0
元时
,就会对其进行透支罚息。在这个例子中,银行将
存款事件放在一个事件流中,将取款事件放在另一个事件流中,如图
6-2
所示。
存款流
透支流
取款流
实例0
时间
时间
时间
6-2:应该以怎样的顺序处理事件
用原始方法来消费和处理事件的话,可能是一个循环处理程序,首先处理
10
元存款事件,
然后处理
25
元取款事件
(会产生负值和透支罚息) ...
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

监控运维实践:原则与策略

监控运维实践:原则与策略

Mike Julian
Kafka权威指南

Kafka权威指南

Neha Narkhede, Gwen Shapira, Todd Palino
Web容量规划之美

Web容量规划之美

Arun Kejariwal, John Allspaw

Publisher Resources

ISBN: 9787115571106