当前位置:网站首页>Module 8 operation

Module 8 operation

2022-06-12 19:25:00 InfoQ

One 、 Homework : Design message queue to store message data  MySQL  form

【 Job requirements 】
1.  Include table name 、 Field 、 Indexes ;
2.  Use words to describe the design ideas and reasons , for example : Why design an index ?
3.  One page  PPT  that will do .
【 Tips 】
1.  You need to consider one table per message queue , Or put all the messages in one table , Add a “ Queue name ” Field of .

Two 、 Table design


CREATE TABLE 
topic_{xxx}
 (
id
 bigint(11) unsigned NOT NULL AUTO_INCREMENT COMMENT ' news  id',
content
 text NOT NULL COMMENT ' The message content ',
producer_id
 bigint(11) unsigned NOT NULL COMMENT ' producer  id',
consumer_id
 bigint(11) unsigned NOT NULL COMMENT ' consumer  id',
consumer_status
 tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT ' Consumption ,0  newly build  1  Consumption success  2  Consumption failure  3  Need retry ',
create_time
 bigint(11) unsigned NOT NULL COMMENT ' Creation time ',
update_time
 bigint(11) unsigned NOT NULL COMMENT ' Update time ',

PRIMARY KEY (
id
),
KEY 
idx_consumer_situation
 (
consumer_id
,
consumer_status
),
KEY 
idx_producer
 (
producer_id
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

3、 ... and 、 Design thinking

Put all the messages in one table , The later expansibility is not good , When a certain amount of data is reached, a sub table must be made . Instead, it's better to create a table directly according to the queue , For example, above  topic_ Is the prefix of the queue , hinder {xxx} You need to replace it with a specific queue name .

Field description :
It has been explained above . I won't repeat .
among  consumer_status  This field determines whether the message has been successfully created 、 Successful consumption 、 Or maybe for some reason , Consumption failed or needs to be retried and marked . The index shows that :

idx_consumer_situation  This index is to facilitate the query of consumers
producer_id  This index facilitates the query of producers' messages
原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206121923480106.html