CREATE TABLE topic (
id int(11) auto_increment NOT NULL,
name varchar(100) DEFAULT "" NOT NULL COMMENT '主题',
description varchar(150) DEFAULT "" NOT NULL COMMENT '描述',
created_at datetime NOT NULL,
PRIMARY KEY(id),
INDEX idx_topic_name(name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='队列主题表';
CREATE TABLE messages_{topic_id} (
id BIGINT UNSIGNED auto_increment NOT NULL,
content text NOT NULL COMMENT '消息体',
created_at datetime NOT NULL,
PRIMARY KEY(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='队列消息表';
CREATE TABLE consumer (
id int(11) auto_increment NOT NULL,
name varchar(100) DEFAULT "" NOT NULL COMMENT '消费者标识',
topic_id int(11) DEFAULT 0 NOT NULL COMMENT '主题id',
commit_msg_id BIGINT UNSIGNED DEFAULT 0 NOT NULL COMMENT '最后消费消息id',
created_at datetime NOT NULL,
updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
PRIMARY KEY(id),
UNIQUE INDEX idx_cousumer_name_topic(name, topic_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='消费者表';
评论