当前位置:网站首页>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
边栏推荐
猜你喜欢

Shell script if statement

消息队列存储消息数据的MySQL表设计

joiplay模拟器报错如何解决

Steven Giesel recently published a 5-part series documenting his first experience building an application with the Uno Platform.

软件开发设计流程

Unity 加载读取PPT

How to use joiplay emulator

Shell programming conditional statement test command Integer value, string comparison Logical test File test

How to adjust Chinese in joiplay simulator

joiplay模拟器如何调中文
随机推荐
46.<list链表的举列>
MySQL数据库进阶篇
MySql数据恢复方法个人总结
【VisDrone数据集】YOLOV4训练VisDrone数据集步骤与结果
机器学习1一回归模型(二)
Linux 部署mysql 5.7全程跟踪 完整步骤 django部署
h264和h265解码上的区别
正则表达式密码策略与正则回溯机制绕过
align-content、justify-content、align-items三个属性的作用和效果
2D转换模块&&媒体查询
Unity 加载读取PPT
Encapsulate and obtain system user information, roles and permission control
Error ER_NOT_SUPPORTED_AUTH_MODE Client does not support authentication protocol requested by serv
Game mall table establishment
怎么开通代付通道接口?
会员生日提前了一天
[In-depth and easy-to-follow FPGA learning 14----------Test case design 2]
joiplay模拟器如何调中文
joiplay模拟器如何使用
pytorch的安装注意事项