README.md 7.5 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 42 43 44




L
luxurong 已提交
45
## main方式启动
L
luxurong 已提交
46 47 48

引入依赖
```markdown
L
luxurong 已提交
49
<!--smqtt依赖 -->
L
luxurong 已提交
50 51 52
<dependency>
  <groupId>io.github.quickmsg</groupId>
  <artifactId>smqtt-core</artifactId>
L
luxurong 已提交
53
  <version>1.0.6</version>
L
luxurong 已提交
54
</dependency>
L
luxurong 已提交
55 56 57 58 59 60 61 62 63 64 65 66
<!--集群依赖 -->
<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 已提交
67 68 69 70 71 72 73

```

阻塞式启动服务:

```markdown

1ssqq1lxr's avatar
1ssqq1lxr 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
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()
           )
           .build()
           .startAwait();
L
luxurong 已提交
98 99 100 101 102 103 104

```

非阻塞式启动服务:

```markdown

L
README  
luxurong 已提交
105
 
1ssqq1lxr's avatar
1ssqq1lxr 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
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()
           )
           .build()
           .start().block();
L
luxurong 已提交
130 131 132 133

```


L
luxurong 已提交
134
## jar方式
L
luxurong 已提交
135 136


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

L
luxurong 已提交
139 140 141
```markdown
  在smqtt-bootstrap/target目录下生成jar
```
L
luxurong 已提交
142

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

L
luxurong 已提交
145 146
```markdown
    
1ssqq1lxr's avatar
1ssqq1lxr 已提交
147 148 149 150 151 152 153 154 155 156 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
# 日志级别 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 已提交
195 196 197
# 容器集群映射主机
# smqtt.cluster.external.host = localhost
# 容器集群映射port
L
luxurong 已提交
198
smqtt.cluster.external.port
L
luxurong 已提交
199

L
luxurong 已提交
200 201
  ```

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

L
luxurong 已提交
204 205 206
```markdown
  java -jar smqtt-bootstrap-1.0.1-SNAPSHOT.jar <conf.properties路径>
```
L
luxurong 已提交
207 208 209



L
luxurong 已提交
210
## docker 方式
L
luxurong 已提交
211

L
luxurong 已提交
212 213

拉取镜像
L
luxurong 已提交
214 215

``` 
L
luxurong 已提交
216
# 拉取docker镜像地址
L
luxurong 已提交
217 218 219
docker pull 1ssqq1lxr/smqtt:latest
```

L
luxurong 已提交
220
启动镜像默认配置
L
luxurong 已提交
221 222

``` 
L
luxurong 已提交
223
# 启动服务
L
luxurong 已提交
224 225 226
docker run -it  -p 1883:1883 1ssqq1lxr/smqtt
```

1ssqq1lxr's avatar
1ssqq1lxr 已提交
227
启动镜像使用自定义配置(同上准备配置文件conf.properties)
L
luxurong 已提交
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244


``` 
# 启动服务
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 已提交
245
```
L
luxurong 已提交
246

1ssqq1lxr's avatar
1ssqq1lxr 已提交
247 248 249 250 251 252 253 254 255 256 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
## 管理后台(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 已提交
284

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

L
luxurong 已提交
288
## wiki地址
L
luxurong 已提交
289

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

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

L
luxurong 已提交
294

L
luxurong 已提交
295
## License
L
luxurong 已提交
296

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

L
luxurong 已提交
299

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

1ssqq1lxr's avatar
pages  
1ssqq1lxr 已提交
303 304 305 306
- 添加微信号`Lemon877164954`,拉入smqtt官方交流群
- 加入qq群 `700152283`