Skip to content

Commit a04d5dd

Browse files
committed
init rep
1 parent 77c3381 commit a04d5dd

File tree

84 files changed

+5712
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+5712
-17
lines changed

.gitignore

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
# Compiled class file
21
*.class
32

4-
# Log file
5-
*.log
6-
7-
# BlueJ files
8-
*.ctxt
9-
10-
# Mobile Tools for Java (J2ME)
11-
.mtj.tmp/
12-
133
# Package Files #
144
*.jar
155
*.war
16-
*.nar
176
*.ear
18-
*.zip
19-
*.tar.gz
20-
*.rar
21-
22-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23-
hs_err_pid*
7+
*.iml
8+
target
9+
classes
10+
*.idea
11+
*.soft.logs
12+
soft.logs

README.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,116 @@
11
# sdmq
22
is a simple delay message queue, based on redis and kotlin
3+
4+
5+
`延时队列`
6+
7+
# 运行模式
8+
9+
* 支持 master,slave (HA)需要配置`jikexiu.registry.serverList` zk集群地址列表
10+
* 支持 cluster 会涉及到分布式锁竞争 效果不是很明显 分布式锁采用`redis``setNx`实现
11+
* StandAlone
12+
13+
推荐使用master slave的模式
14+
15+
##### Usage
16+
17+
#### 消息体
18+
19+
以JSON数据格式参数 目前只提供了`http`协议
20+
21+
22+
* body 业务消息体
23+
* delay 延时毫秒 距`createTime`的间隔毫秒数
24+
* id 任务ID 系统自动生成 任务创建成功返回
25+
* status 状态 默认不填写
26+
* topic 标题
27+
* subtopic 保留字段
28+
* ttl 保留字段
29+
* createTime 创建任务时间 非必填 系统默认
30+
31+
#### 添加任务
32+
33+
34+
````
35+
/push
36+
POST application/json
37+
38+
{"body":"{ffff}","delay":56600,"id":"20","status":0,"topic":"ces","subtopic":"",ttl":12}
39+
````
40+
41+
#### 删除任务
42+
43+
删除任务 需要记录一个JobId
44+
45+
````
46+
/delete?jobId=xxx
47+
GET
48+
````
49+
#### 恢复单个任务
50+
51+
用于任务错乱 脑裂情况 根据日志恢复任务
52+
53+
````
54+
/reStoreJob?JobId=xxx
55+
GET
56+
````
57+
#### 恢复所有未完成的任务
58+
59+
根据日志恢复任务
60+
61+
````
62+
/reStore?expire=true
63+
GET
64+
````
65+
66+
参数`expire` 表示是否需要恢复已过期还未执行的数据
67+
68+
#### 清空队列数据
69+
70+
根据日志中未完成的数据清空队列中全部数据
71+
72+
`清空之后 会删除缓存中的所有任务`
73+
````
74+
/clearAll
75+
GET
76+
````
77+
78+
79+
80+
#### 客户端获取队列方式
81+
82+
目前默认实现了`rocketmq`的推送方式。暂时就不用自己去实现推拉数据了。直接强依赖MQ。
83+
84+
##### 消息体中消息与`rocketmq`消息字段对应关系
85+
86+
DelayQueue | rocketMQ | 备注|
87+
--- | --- |---
88+
topic | topic | |
89+
subtopic | subtopic | |
90+
body | 消息内容 | 消息内容 |
91+
92+
93+
94+
## 后期优化
95+
96+
* 分区(buck)支持动态设置
97+
* redis与数据库数据一致性的问题 (`重要`
98+
* 实现自己的推拉机制
99+
* 支持可切换实现方式 当前强依赖redis 只有这么1个实现
100+
* 支持Web控制台管理队列
101+
* 实现消息消费`TTL`机制
102+
103+
## 测试
104+
需要配置好数据库地址和redis的地址 如果不是单机模式 也需要配置好zookeep
105+
106+
运行测试类`io.sdmq.FixTest`添加任务到队列中
107+
108+
启动`Bootstarp`消费前面添加数据 为了方便查询效果 默认的消费方式是`consoleCQ` 控制台输出
109+
110+
## 更新日志
111+
112+
* 2017年11月21日14:34:39 支持`restful`清空队列数据
113+
* 2018年03月19日14:26:56 支持配置消费方式 默认为`jmsCQ` 在不修改代码的情况下覆盖方式 `-DClassName=xxxx`
114+
115+
116+

pom.xml

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>io.sdmq</groupId>
7+
<artifactId>sdmq-core</artifactId>
8+
<version>0.0.1</version>
9+
<packaging>jar</packaging>
10+
11+
<name>sdmq</name>
12+
<url>https://github.com/peachyy/sdmq.git</url>
13+
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
17+
<spring.version>4.2.3.RELEASE</spring.version>
18+
<boot.version>1.4.3.RELEASE</boot.version>
19+
<java.version>1.7</java.version>
20+
<maven.compiler.source>${java.version}</maven.compiler.source>
21+
<maven.compiler.target>${java.version}</maven.compiler.target>
22+
<guava.version>18.0</guava.version>
23+
<commons.fileupload.version>1.3.1</commons.fileupload.version>
24+
<fastjson.version>1.2.6</fastjson.version>
25+
<curator.version>2.10.0</curator.version>
26+
<useUniqueVersions>false</useUniqueVersions>
27+
</properties>
28+
<dependencyManagement>
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-dependencies</artifactId>
33+
<version>${boot.version}</version>
34+
<type>pom</type>
35+
<scope>import</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>com.google.guava</groupId>
39+
<artifactId>guava</artifactId>
40+
<version>${guava.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.apache.commons</groupId>
44+
<artifactId>commons-lang3</artifactId>
45+
<version>3.1</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>commons-codec</groupId>
49+
<artifactId>commons-codec</artifactId>
50+
<version>1.9</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>commons-beanutils</groupId>
54+
<artifactId>commons-beanutils</artifactId>
55+
<version>1.9.2</version>
56+
</dependency>
57+
<!--swagger ui-->
58+
<dependency>
59+
<groupId>io.springfox</groupId>
60+
<artifactId>springfox-swagger2</artifactId>
61+
<version>2.4.0</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>io.springfox</groupId>
65+
<artifactId>springfox-swagger-ui</artifactId>
66+
<version>2.4.0</version>
67+
</dependency>
68+
<!--json-->
69+
<dependency>
70+
<groupId>com.alibaba</groupId>
71+
<artifactId>fastjson</artifactId>
72+
<version>${fastjson.version}</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>com.alibaba</groupId>
76+
<artifactId>druid</artifactId>
77+
<version>1.0.14</version>
78+
</dependency>
79+
<dependency>
80+
<groupId>mysql</groupId>
81+
<artifactId>mysql-connector-java</artifactId>
82+
<version>5.1.35</version>
83+
</dependency>
84+
<dependency>
85+
<groupId>org.apache.curator</groupId>
86+
<artifactId>curator-recipes</artifactId>
87+
<version>${curator.version}</version>
88+
</dependency>
89+
<dependency>
90+
<groupId>org.apache.curator</groupId>
91+
<artifactId>curator-client</artifactId>
92+
<version>${curator.version}</version>
93+
</dependency>
94+
95+
</dependencies>
96+
</dependencyManagement>
97+
98+
99+
<dependencies>
100+
<dependency>
101+
<groupId>org.springframework.boot</groupId>
102+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
103+
<optional>true</optional>
104+
</dependency>
105+
<dependency>
106+
<groupId>org.springframework.boot</groupId>
107+
<artifactId>spring-boot-starter-web</artifactId>
108+
<exclusions>
109+
<exclusion>
110+
<groupId>org.springframework.boot</groupId>
111+
<artifactId>spring-boot-starter-tomcat</artifactId>
112+
</exclusion>
113+
114+
</exclusions>
115+
</dependency>
116+
<!--<dependency>-->
117+
<!--<groupId>com.fasterxml.jackson.core</groupId>-->
118+
<!--<artifactId>jackson-databind</artifactId>-->
119+
<!--</dependency>-->
120+
<dependency>
121+
<groupId>org.springframework.boot</groupId>
122+
<artifactId>spring-boot-starter-undertow</artifactId>
123+
<optional>true</optional>
124+
</dependency>
125+
<dependency>
126+
<groupId>org.springframework.boot</groupId>
127+
<artifactId>spring-boot-starter-actuator</artifactId>
128+
<optional>true</optional>
129+
</dependency>
130+
<dependency>
131+
<groupId>org.springframework.boot</groupId>
132+
<artifactId>spring-boot-starter-data-redis</artifactId>
133+
<optional>true</optional>
134+
</dependency>
135+
<dependency>
136+
<groupId>org.springframework.boot</groupId>
137+
<artifactId>spring-boot-starter-test</artifactId>
138+
</dependency>
139+
<dependency>
140+
<groupId>org.springframework</groupId>
141+
<artifactId>spring-context-support</artifactId>
142+
</dependency>
143+
<dependency>
144+
<groupId>mysql</groupId>
145+
<artifactId>mysql-connector-java</artifactId>
146+
</dependency>
147+
<dependency>
148+
<groupId>com.alibaba</groupId>
149+
<artifactId>fastjson</artifactId>
150+
</dependency>
151+
<!---->
152+
<dependency>
153+
<groupId>com.alibaba</groupId>
154+
<artifactId>druid</artifactId>
155+
</dependency>
156+
<dependency>
157+
<groupId>com.google.guava</groupId>
158+
<artifactId>guava</artifactId>
159+
</dependency>
160+
<dependency>
161+
<groupId>com.alibaba.rocketmq</groupId>
162+
<artifactId>rocketmq-client</artifactId>
163+
<version>3.2.6</version>
164+
</dependency>
165+
<dependency>
166+
<groupId>org.apache.curator</groupId>
167+
<artifactId>curator-recipes</artifactId>
168+
</dependency>
169+
<dependency>
170+
<groupId>org.apache.curator</groupId>
171+
<artifactId>curator-client</artifactId>
172+
</dependency>
173+
</dependencies>
174+
175+
176+
<build>
177+
<sourceDirectory>src/main/java</sourceDirectory>
178+
<plugins>
179+
<plugin>
180+
<groupId>org.springframework.boot</groupId>
181+
<artifactId>spring-boot-maven-plugin</artifactId>
182+
<version>${boot.version}</version>
183+
<configuration>
184+
<fork>true</fork>
185+
<mainClass>io.sdmq.Bootstarp</mainClass>
186+
</configuration>
187+
<executions>
188+
<execution>
189+
<goals>
190+
<goal>repackage</goal>
191+
</goals>
192+
</execution>
193+
</executions>
194+
</plugin>
195+
<plugin>
196+
<groupId>org.apache.maven.plugins</groupId>
197+
<artifactId>maven-assembly-plugin</artifactId>
198+
<version>2.5.2</version>
199+
<configuration>
200+
<descriptor>src/main/assembly/assembly.xml</descriptor>
201+
<finalName>${project.artifactId}-${project.version}</finalName>
202+
</configuration>
203+
<executions>
204+
<execution>
205+
<id>make-assembly</id>
206+
<phase>install</phase>
207+
<goals>
208+
<goal>single</goal>
209+
</goals>
210+
</execution>
211+
</executions>
212+
</plugin>
213+
<plugin>
214+
<groupId>org.apache.maven.plugins</groupId>
215+
<artifactId>maven-surefire-plugin</artifactId>
216+
<version>2.18.1</version>
217+
<configuration>
218+
<skip>true</skip>
219+
<includes>
220+
<include>**/*Test.java</include>
221+
</includes>
222+
</configuration>
223+
<dependencies>
224+
<dependency>
225+
<groupId>org.apache.maven.surefire</groupId>
226+
<artifactId>surefire-junit47</artifactId>
227+
<version>2.18.1</version>
228+
</dependency>
229+
</dependencies>
230+
</plugin>
231+
<plugin>
232+
<groupId>org.apache.maven.plugins</groupId>
233+
<artifactId>maven-jar-plugin</artifactId>
234+
<version>2.6</version>
235+
<configuration>
236+
<archive>
237+
<manifest>
238+
<addClasspath>true</addClasspath>
239+
<classpathPrefix>lib/</classpathPrefix>
240+
</manifest>
241+
</archive>
242+
</configuration>
243+
</plugin>
244+
</plugins>
245+
246+
</build>
247+
248+
249+
</project>

0 commit comments

Comments
 (0)