File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
docs/system-design/distributed-system/message-queue Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -111,13 +111,18 @@ ZooKeeper 主要为 Kafka 提供元数据的管理的功能。
111111
112112### Kafka 如何保证消息的消费顺序?
113113
114- 我们在使用消息队列的过程中经常有业务场景需要严格保证消息的消费顺序,比如我们同时发了 2 个消息,这 2 个消息对应的操作分别对应的数据库操作是:更改用户会员等级、根据会员等级计算订单价格。假如这两条消息的消费顺序不一样造成的最终结果就会截然不同。
114+ 我们在使用消息队列的过程中经常有业务场景需要严格保证消息的消费顺序,比如我们同时发了 2 个消息,这 2 个消息对应的操作分别对应的数据库操作是:
115+
116+ 1 . 更改用户会员等级。
117+ 2 . 根据会员等级计算订单价格。
118+
119+ 假如这两条消息的消费顺序不一样造成的最终结果就会截然不同。
115120
116121我们知道 Kafka 中 Partition(分区)是真正保存消息的地方,我们发送的消息都被放在了这里。而我们的 Partition(分区) 又存在于 Topic(主题) 这个概念中,并且我们可以给特定 Topic 指定多个 Partition。
117122
118123![ ] ( https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019-11/KafkaTopicPartionsLayout.png )
119124
120- 每次添加消息到 Partition(分区) 的时候都会采用尾加法,如上图所示。Kafka 只能为我们保证 Partition(分区) 中的消息有序,而不能保证 Topic(主题) 中的 Partition(分区) 的有序。
125+ 每次添加消息到 Partition(分区) 的时候都会采用尾加法,如上图所示。 ** Kafka 只能为我们保证 Partition(分区) 中的消息有序。 **
121126
122127> 消息在被追加到 Partition(分区)的时候都会分配一个特定的偏移量(offset)。Kafka 通过偏移量(offset)来保证消息在分区内的顺序性。
123128
You can’t perform that action at this time.
0 commit comments