当前位置:网站首页>MySQL table design for message queue to store message data
MySQL table design for message queue to store message data
2022-07-31 00:17:00 【InfoQ】
Analysis of message queue storage structure
message table
- Because the data is grouped in the design of the system architecture, a field representing the grouping is required in the table: shard_id.The shard_id of each group of data grouping clusters is fixed.This is similar to the partition design of kafka, different consumers can pull different shards to achieve the purpose of accelerating consumption;
- Here design eachEach topic is stored in a separate table, that is,message_{topic}, the reason is 1. MySQL theoretically supports hundreds of millions of tables, which can meet the number of topics required 2.Using a single table can isolate the impact of each topic (physically and logically). 3. It is relatively simple to use, because only the messages of the topic can be stored in a single table, and the id can also be auto-incremented.

consume_log table
- We support multiple consumer groups, each consumer group shares a consumption progress record, so the table needs to have a group field to distinguish which consumer isThe consumption record of the group;
- The consumption offset is the most important, which records the consumption data, which is identified by offset, that is, messageThe msg_id in the table, because msg_id is strictly increasing under one data group and one topic;
Index Analysis
Send messages
- CustomersThe end completes the shard routing, assigns it to a shard, and sends the message data
- The message queue server finds the corresponding message table message_{topic} according to the topic, and then insert data, msg_id is incremented automatically
Consume message
- The client completes the routing of the fragmentation and sends thePull the message from the corresponding server, bring the parameters topic, group
- to query the consumer_log table, find the corresponding data through the index according to the topic and group, and take out the offset
- Query the corresponding message table according to the offset, find the record of the next offset through the primary key id, take it out and prepare to return
- Update the offset information of consumer_log
- Return data
message expiration
Index summary
- message_log table addedidx_topic_group, is the combined index of topic+group
- message table addedidx_born_date, is the index of born_date
边栏推荐
- Xss target drone training [success when pop-up window is realized]
- DNS resolution process [visit website]
- Bugku sql注入
- What are the efficient open source artifacts of VSCode
- Gabor filter study notes
- A Brief Talk About MPI
- Homework: iptables prevent nmap scan and binlog
- VSCode高效开源神器有哪些
- pytorch双线性插值
- How to ensure the consistency of database and cache data?
猜你喜欢
随机推荐
How to solve the error of joiplay simulator
会议OA项目待开会议、所有会议功能
.NET 跨平台应用开发动手教程 |用 Uno Platform 构建一个 Kanban-style Todo App
Shell script if statement
Axure Carousel
leetcode 406. Queue Reconstruction by Height
IOT cross-platform component design scheme
In-depth understanding of the auto-increment operator from two error-prone written test questions
align-content、justify-content、align-items三个属性的作用和效果
Optimization of aggregate mentioned at DATA AI Summit 2022
状态机动态规划之股票问题总结
从笔试包装类型的11个常见判断是否相等的例子理解:包装类型、自动装箱与拆箱的原理、装箱拆箱的发生时机、包装类型的常量池技术
H5跳转微信公众号解决方案
数据库的严格模式
360核心安全大脑3.0正式发布,构建政企用户的“能力中枢平台”
web漏洞之需要准备的工作
binglog日志追踪:数据备份并备份追踪
registers (assembly language)
firewalld
How to import game archives in joiplay emulator








