https://github.com/limen/tmq
Timing Message Queue
https://github.com/limen/tmq
java queue schedule timing
Last synced: 5 months ago
JSON representation
Timing Message Queue
- Host: GitHub
- URL: https://github.com/limen/tmq
- Owner: limen
- Created: 2020-04-26T05:22:58.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-21T03:26:45.000Z (about 4 years ago)
- Last Synced: 2025-05-24T01:47:08.952Z (about 1 year ago)
- Topics: java, queue, schedule, timing
- Language: Java
- Homepage:
- Size: 18.6 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TMQ: Timing Message Queue
定时消息队列
介绍 [TMQ:定时消息队列](https://blog.csdn.net/u010205879/article/details/106094316)
## API
### 投递消息
```
push(MessageInterface msg)
```
### 拉取消息
```
pull(Date t)
```
### 查询消息
```
poll(String msgId)
```
### 获取分片大小
```
size(Date t)
```
### 更新消息
```
consumed(MessageInterface msg)
```
## 开始使用
### 准备基础环境
MySQL连接
```
jdbc:mysql://127.0.0.1:3306/mydemo
```
Redis连接
```
localhost:6379
```
### 创建数据表
```
CREATE TABLE tmq_queue (
id INT NOT NULL AUTO_INCREMENT,
queue_name VARCHAR(64) NOT NULL COMMENT '队列名称',
msg_id VARCHAR(24) NOT NULL COMMENT '消息ID',
body VARCHAR(1024) NOT NULL COMMENT '消息体',
schedule DATETIME NOT NULL COMMENT '投递时间',
status TINYINT NOT NULL COMMENT '消息状态',
receive_at DATETIME NOT NULL COMMENT '接收时间',
consume_at DATETIME COMMENT '消费时间',
PRIMARY KEY (id),
UNIQUE KEY idx_msg_id (msg_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
```
### 测试
见 com.limengxiang.tmq.TimingMessageQueueTest
### 查看数据
MySQL
```
> SELECT * FROM tmq_queue;
```
Redis
```
> keys *:slice:*
> lrange {slice key} 0 -1
```
## 消息ID生成算法
参考 [xid](https://github.com/rs/xid)