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

微服务与事件驱动架构

by Adam Bellemare
October 2021
Beginner to intermediate
250 pages
7h 11m
Chinese
Posts & Telecom Press
Content preview from 微服务与事件驱动架构
68
5
在重新分配分区时,工作通常会暂时挂起以避免争用分区的情况。这可以确保在分配分区
给新实例之前,其他实例不再处理任何被废除的分区,从而消除任何潜在的重复输出。
5.4.1
 使用分区分配器分配分区
处理大数据通常需要多个消费者微服务实例,无论是专用流处理框架还是基础的生产者
/
消费者实现。
分区分配器
可以确保将分区以均衡和公平的方式分配给处理实例。
每当在消费者组中添加或删除消费者实例时,分区分配器都负责重新分配分区。根据所选
择的事件代理,此组件可能被构建到消费者客户端中,或者由事件代理维护。
5.4.2
 分配协同分区
分区分配器还负责确保满足所有协同分区的需求。所有标记为协同分区的分区必须分配给
同一个消费者实例。这将确保为给定的微服务实例分配正确的事件数据子集,以执行其业
务逻辑。这方面的最佳实践是分区分配器实现校验机制,可以查看事件流是否具有相等的
分区数,并在不相等时抛出异常。
5.4.3
 分区分配策略
在消费者实例处理能力相同的情况下,分区分配算法的目标是确保分区在消费者实例中均
匀分布。分区分配算法也可能有次要目标,比如减少在再平衡期间重新分配的分区数量。
当处理跨多个数据存储实例的物化状态分片时,这一点尤其重要,因为重新分配分区会导
致将来的更新进入错误的分片。第
7
章将进一步探讨关于内部状态存储的概念。
分配分区有许多常用的策略。默认策略可能会因框架或实现的不同而有所不同,但以下
3
种策略往往是最常用的。
1.
循环分配
所有分区都被记录到一个列表中,并以循环方式分配给每个消费者实例。为协同分区流保 ...
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