README.md 7.9 KB
Newer Older
1ssqq1lxr's avatar
log  
1ssqq1lxr 已提交
1
## ![image](icon/logo.png) SMQTT是一款开源的MQTT消息代理Broker,
L
luxurong 已提交
2

L
luxurong 已提交
3
SMQTT基于Netty开发,底层采用Reactor3反应堆模型,支持单机部署,支持容器化部署,具备低延迟,高吞吐量,支持百万TCP连接,同时支持多种协议交互,是一款非常优秀的消息中间件!
L
luxurong 已提交
4
## smqtt目前拥有的功能如下:
L
icon  
luxurong 已提交
5
![架构图](icon/component.png)
L
luxurong 已提交
6 7

1.  消息质量等级实现(支持qos0,qos1,qos2)
L
luxurong 已提交
8 9 10 11
2.  topicFilter支持
    - topic分级(test/test)
    - +支持(单层匹配)
    - #支持(多层匹配)
L
luxurong 已提交
12
2.  会话消息
L
luxurong 已提交
13 14
    - 默认内存存储
    - 支持持久化(redis/db)
L
luxurong 已提交
15
3.  保留消息
L
luxurong 已提交
16 17
     - 默认内存存储
     - 支持持久化(redis/db)
L
luxurong 已提交
18
4.  遗嘱消息
L
luxurong 已提交
19
     > 设备掉线时候触发
L
luxurong 已提交
20
5.  客户端认证
L
luxurong 已提交
21
     - 支持spi注入外部认证
L
luxurong 已提交
22
6.  tls加密
L
luxurong 已提交
23
     - 支持tls加密(mqtt端口/http端口)
L
luxurong 已提交
24
7.  websocket协议支持
L
luxurong 已提交
25
     > 使用websocket协议包装mqtt协议
L
luxurong 已提交
26
8.  http协议交互
L
luxurong 已提交
27 28
    - 支持http接口推送消息
    - 支持spi扩展http接口
L
luxurong 已提交
29
9.  SPI接口扩展支持
L
luxurong 已提交
30 31 32 33 34 35
    - 消息管理接口(会话消息/保留消息管理)
    - 通道管理接口 (管理系统的客户端连接)
    - 认证接口 (用于自定义外部认证)
    - 拦截器  (用户自定义拦截消息)
10. 集群支持(gossip协议实现)
11. 容器化支持 
L
luxurong 已提交
36
    > 默认镜像最新tag: 1ssqq1lxr/smqtt
1ssqq1lxr's avatar
1ssqq1lxr 已提交
37
12. 持久化支持(session 保留消息)
L
luxurong 已提交
38 39
13. 管理后台
    > 请参考smqtt文档如何启动管理后台
L
luxurong 已提交
40
   
L
luxurong 已提交
41

L
luxurong 已提交
42
## 尝试一下
L
luxurong 已提交
43

L
luxurong 已提交
44 45 46 47 48 49 50
> 大家不要恶意链接,谢谢!

|  管理   | 说明  | 其他  |
|  ----  | ----  |----  |
| 123.57.69.210:1883  | mqtt端口 |用户名:smqtt 密码:smqtt |
| 123.57.69.210:8999  | mqtt over websocket |用户名:smqtt 密码:smqtt  |
| http://123.57.69.210:60000/smqtt/admin | 管理后台 |用户名:smqtt 密码:smqtt  |
L
luxurong 已提交
51 52


L
luxurong 已提交
53
## main方式启动
L
luxurong 已提交
54 55 56

引入依赖
```markdown
L
luxurong 已提交
57
<!--smqtt依赖 -->
L
luxurong 已提交
58 59 60
<dependency>
  <groupId>io.github.quickmsg</groupId>
  <artifactId>smqtt-core</artifactId>
L
luxurong 已提交
61
  <version>1.0.6</version>
L
luxurong 已提交
62
</dependency>
L
luxurong 已提交
63 64 65 66 67 68 69 70 71 72 73 74
<!--集群依赖 -->
<dependency>
   <artifactId>smqtt-registry-scube</artifactId>
   <groupId>io.github.quickmsg</groupId>
   <version>1.0.6</version>
</dependency>
<!--管理ui依赖 -->
<dependency>
   <artifactId>smqtt-ui</artifactId>
   <groupId>io.github.quickmsg</groupId>
   <version>1.0.6</version> 
</dependency>
L
luxurong 已提交
75 76 77 78 79 80 81

```

阻塞式启动服务:

```markdown

1ssqq1lxr's avatar
1ssqq1lxr 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
Bootstrap.builder()
          .rootLevel(Level.INFO)
          .wiretap(false)
          .port(8555)
          .websocketPort(8999)
          .options(channelOptionMap -> { })//netty options设置
          .childOptions(channelOptionMap -> { }) //netty childOptions设置
          .highWaterMark(1000000)
          .reactivePasswordAuth((U, P) -> true)
          .lowWaterMark(1000)
          .ssl(false)
          .sslContext(new SslContext("crt", "key"))
          .isWebsocket(true)
          .httpOptions(Bootstrap.HttpOptions.builder().enableAdmin(true).ssl(false).accessLog(true).build())
          .clusterConfig(
               ClusterConfig.builder()
                                .clustered(false)
                                .port(7773)
                                .nodeName("node-2")
                                .clusterUrl("127.0.0.1:7771,127.0.0.1:7772")
                                .build()
           )
L
doc  
luxurong 已提交
104
           .started(bootstrap->{})
1ssqq1lxr's avatar
1ssqq1lxr 已提交
105 106
           .build()
           .startAwait();
L
luxurong 已提交
107 108 109 110 111 112 113

```

非阻塞式启动服务:

```markdown

L
README  
luxurong 已提交
114
 
1ssqq1lxr's avatar
1ssqq1lxr 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
Bootstrap bootstrap = Bootstrap.builder()
          .rootLevel(Level.INFO)
          .wiretap(false)
          .port(8555)
          .websocketPort(8999)
          .options(channelOptionMap -> { })//netty options设置
          .childOptions(channelOptionMap -> { }) //netty childOptions设置
          .highWaterMark(1000000)
          .reactivePasswordAuth((U, P) -> true)
          .lowWaterMark(1000)
          .ssl(false)
          .sslContext(new SslContext("crt", "key"))
          .isWebsocket(true)
          .httpOptions(Bootstrap.HttpOptions.builder().enableAdmin(true).ssl(false).accessLog(true).build())
          .clusterConfig(
               ClusterConfig.builder()
                                .clustered(false)
                                .port(7773)
                                .nodeName("node-2")
                                .clusterUrl("127.0.0.1:7771,127.0.0.1:7772")
                                .build()
           )
L
doc  
luxurong 已提交
137
           .started(bootstrap->{})
1ssqq1lxr's avatar
1ssqq1lxr 已提交
138 139
           .build()
           .start().block();
L
luxurong 已提交
140 141 142 143

```


L
luxurong 已提交
144
## jar方式
L
luxurong 已提交
145 146


1ssqq1lxr's avatar
1ssqq1lxr 已提交
147
1. 下载源码 mvn compile package -Dmaven.test.skip=true -P jar,web
L
luxurong 已提交
148

L
luxurong 已提交
149 150 151
```markdown
  在smqtt-bootstrap/target目录下生成jar
```
L
luxurong 已提交
152

1ssqq1lxr's avatar
1ssqq1lxr 已提交
153
2. 准备配置文件 config.properties
L
luxurong 已提交
154

L
luxurong 已提交
155 156
```markdown
    
1ssqq1lxr's avatar
1ssqq1lxr 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
# 日志级别 ALL|TRACE|DEBUG|INFO|WARN|ERROR|OFF
smqtt.log.level=INFO
# 开启tcp端口
smqtt.tcp.port=1883
# 高水位
smqtt.tcp.lowWaterMark=4000000
# 低水位
smqtt.tcp.highWaterMark=80000000
# 开启ssl加密
smqtt.tcp.ssl=false
# 证书crt smqtt.tcp.ssl.crt =
# 证书key smqtt.tcp.ssl.key =
# 开启日志
smqtt.tcp.wiretap=false
# boss线程
smqtt.tcp.bossThreadSize=4
# work线程
smqtt.tcp.workThreadSize=8
# websocket端口
smqtt.websocket.port=8999
# websocket开启
smqtt.websocket.enable=true
# smqtt用户
smqtt.tcp.username=smqtt
# smqtt密码
smqtt.tcp.password=smqtt
# 开启http
smqtt.http.enable=true
# 开启http日志
smqtt.http.accesslog=true
# 开启ssl
smqtt.http.ssl.enable=false
# smqtt.http.ssl.crt =
# smqtt.http.ssl.key =
# 开启管理后台(必须开启http)
smqtt.http.admin.enable=true
# 管理后台登录用户
smqtt.http.admin.username=smqtt
# 管理后台登录密码
smqtt.http.admin.password=smqtt
# 开启集群
smqtt.cluster.enable=false
# 集群节点地址
smqtt.cluster.url=127.0.0.1:7771,127.0.0.1:7772
# 节点端口
smqtt.cluster.port=7771
# 节点名称
smqtt.cluster.node=node-1
L
luxurong 已提交
205 206 207
# 容器集群映射主机
# smqtt.cluster.external.host = localhost
# 容器集群映射port
L
luxurong 已提交
208
smqtt.cluster.external.port
L
luxurong 已提交
209

L
luxurong 已提交
210 211
  ```

1ssqq1lxr's avatar
1ssqq1lxr 已提交
212
3. 启动服务
L
luxurong 已提交
213

L
luxurong 已提交
214 215 216
```markdown
  java -jar smqtt-bootstrap-1.0.1-SNAPSHOT.jar <conf.properties路径>
```
L
luxurong 已提交
217 218 219



L
luxurong 已提交
220
## docker 方式
L
luxurong 已提交
221

L
luxurong 已提交
222 223

拉取镜像
L
luxurong 已提交
224 225

``` 
L
luxurong 已提交
226
# 拉取docker镜像地址
L
luxurong 已提交
227 228 229
docker pull 1ssqq1lxr/smqtt:latest
```

L
luxurong 已提交
230
启动镜像默认配置
L
luxurong 已提交
231 232

``` 
L
luxurong 已提交
233
# 启动服务
L
luxurong 已提交
234 235 236
docker run -it  -p 1883:1883 1ssqq1lxr/smqtt
```

1ssqq1lxr's avatar
1ssqq1lxr 已提交
237
启动镜像使用自定义配置(同上准备配置文件conf.properties)
L
luxurong 已提交
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254


``` 
# 启动服务
docker run -it  -v <配置文件路径目录>:/conf -p 1883:1883  -p 1999:1999 1ssqq1lxr/smqtt
```


## 测试服务(启动http端口)

- 启动客户端订阅主题 test/+

- 使用http接口推送mqtt消息

``` 
# 推送消息
curl -H "Content-Type: application/json" -X POST -d '{"topic": "test/teus", "qos":2, "retain":true, "message":"我来测试保留消息3" }' "http://localhost:1999/smqtt/publish"
L
luxurong 已提交
255
```
L
luxurong 已提交
256

1ssqq1lxr's avatar
1ssqq1lxr 已提交
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
## 管理后台(60000端口)

### 如何开启

    
- main启动
    
   设置httpOptions && enableAdmin = true
   
    ``` 
    Bootstrap.httpOptions(Bootstrap.HttpOptions.builder().enableAdmin(true).ssl(false).accessLog(true).build())
  
    ```
- jar / docker 启动
    
   设置config.properties
   
    ``` 
    # 开启http
    smqtt.http.enable=true
    # 开启http日志
    smqtt.http.accesslog=true
    # 开启ssl
    smqtt.http.ssl.enable=false
    # smqtt.http.ssl.crt =
    # smqtt.http.ssl.key =
    # 开启管理后台(必须开启http)
    smqtt.http.admin.enable=true
    # 管理后台登录用户
    smqtt.http.admin.username=smqtt
    # 管理后台登录密码
    smqtt.http.admin.password=smqtt  
    ```

### 页面预览

![image](icon/admin.png)
L
luxurong 已提交
294

1ssqq1lxr's avatar
1ssqq1lxr 已提交
295 296
## 压测文档
[点这里](https://blog.csdn.net/JingleYe/article/details/118190935)
L
luxurong 已提交
297

L
luxurong 已提交
298
## wiki地址
L
luxurong 已提交
299

1ssqq1lxr's avatar
pages  
1ssqq1lxr 已提交
300 301
集群类配置参考文档:

L
luxurong 已提交
302
[smqtt文档](https://quickmsg.github.io/smqtt)
L
luxurong 已提交
303

L
luxurong 已提交
304

L
luxurong 已提交
305
## License
L
luxurong 已提交
306

L
luxurong 已提交
307
[Apache License, Version 2.0](https://github.com/quickmsg/smqtt/blob/main/LICENSE)
L
luxurong 已提交
308

L
luxurong 已提交
309

1ssqq1lxr's avatar
pages  
1ssqq1lxr 已提交
310
## 麻烦关注下公众号!
L
luxurong 已提交
311
![image](icon/icon.jpg)
L
luxurong 已提交
312

1ssqq1lxr's avatar
pages  
1ssqq1lxr 已提交
313 314 315 316
- 添加微信号`Lemon877164954`,拉入smqtt官方交流群
- 加入qq群 `700152283`