写点什么

Design a messaging queue table in MySQL

作者:David
  • 2022-12-17
    澳大利亚
  • 本文字数:824 字

    阅读完需:约 3 分钟

Background

Implement a messaging queue table in MySQL, including

  • table name, columns and index

  • thoughts behind the design

Hit

  • Use one table for each message queue, or put all messages in one table and add a "queue name" field.

Thoughts

  • Different queues/jobs have different requirements. From a scalability perspective, using separate tables is a better solution.

  • From a priority perspective, we can use the message-id (auto-increment primary key) or store a specific priority weight in the database with each message.

  • For high availability, we can use a master-slave database pattern.

  • Have a success consumption log table and an error log table for each queue. The success consumption log table is for auditing purposes and the error log table is for retrying mechanism.

  • Have a clean-up schedule job to delete any data older than N days (based on the business requirement).


MySQL table

Queue message table

# table name, eg for queue foofoo_queue
# columnid auto-increment primary keyname queue name (varchar)status queue message status (enum)message (varchar)priority (enum)created_at (datetime)
复制代码

Success consumption log table

# table name, eg for queue foofoo_consumption_event
# columnid auto-increment primary keyname queue name (varchar)status queue message status (enum)message (varchar)priority (enum)created_at (datetime)
复制代码

Error log table

# table name, eg for queue foofoo_failed_event
# columnid auto-increment primary keyname queue name (varchar)status queue message status (enum)message (varchar)priority (enum)error_message (varchar)error_code (varchar)created_at (datetime)
复制代码


用户头像

David

关注

还未添加个人签名 2018-03-18 加入

还未添加个人简介

评论

发布
暂无评论
Design a messaging queue table in MySQL_#架构实战营_David_InfoQ写作社区