README.md 10.2 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协议支持x
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
doc  
luxurong 已提交
38
13. 规则引擎支持(文档需要赞助提供)
L
luxurong 已提交
39 40
13. 管理后台
    > 请参考smqtt文档如何启动管理后台
L
luxurong 已提交
41
   
L
luxurong 已提交
42

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

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

|  管理   | 说明  | 其他  |
|  ----  | ----  |----  |
| 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 已提交
52 53


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

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

阻塞式启动服务:

```markdown
L
luxurong 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
  Bootstrap bootstrap = Bootstrap.builder()
                .rootLevel(Level.DEBUG)
                .tcpConfig(
                        BootstrapConfig
                                .TcpConfig
                                .builder()
                                .port(8888)
                                .username("smqtt")
                                .password("smqtt")
                                .build())
                .httpConfig(
                        BootstrapConfig
                                .HttpConfig
                                .builder()
                                .enable(true)
                                .accessLog(true)
                                .build())
                .clusterConfig(
                        BootstrapConfig.
                                ClusterConfig
                                .builder()
                                .enable(true)
                                .namespace("smqtt")
                                .node("node-1")
1ssqq1lxr's avatar
1ssqq1lxr 已提交
105
                                .port(7773)
L
luxurong 已提交
106 107 108 109
                                .url("127.0.0.1:7771,127.0.0.1:7772").
                                build())
                .build()
                .startAwait();
L
luxurong 已提交
110 111 112 113 114
```

非阻塞式启动服务:

```markdown
L
luxurong 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

  Bootstrap bootstrap = Bootstrap.builder()
                .rootLevel(Level.DEBUG)
                .tcpConfig(
                        BootstrapConfig
                                .TcpConfig
                                .builder()
                                .port(8888)
                                .username("smqtt")
                                .password("smqtt")
                                .build())
                .httpConfig(
                        BootstrapConfig
                                .HttpConfig
                                .builder()
                                .enable(true)
                                .accessLog(true)
                                .build())
                .clusterConfig(
                        BootstrapConfig.
                                ClusterConfig
                                .builder()
                                .enable(true)
                                .namespace("smqtt")
                                .node("node-1")
1ssqq1lxr's avatar
1ssqq1lxr 已提交
140
                                .port(7773)
L
luxurong 已提交
141 142 143 144
                                .url("127.0.0.1:7771,127.0.0.1:7772").
                                build())
                .build()
                .start().block();
L
luxurong 已提交
145 146
```

L
luxurong 已提交
147
## jar方式
L
luxurong 已提交
148

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

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

L
yaml  
luxurong 已提交
155
2. 准备配置文件 config.yaml
L
luxurong 已提交
156

L
luxurong 已提交
157
```markdown
L
yaml  
luxurong 已提交
158 159 160 161 162 163 164
smqtt:
  logLevel: DEBUG # 系统日志
  tcp: # tcp配置
    port: 1883 # mqtt端口号
    username: smqtt # mqtt连接默认用户名  生产环境建议spi去注入PasswordAuthentication接口
    password: smqtt  # mqtt连接默认密码 生产环境建议spi去注入PasswordAuthentication接口
    wiretap: true  # 二进制日志 前提是 smqtt.logLevel = DEBUG
L
doc  
luxurong 已提交
165 166 167 168
    bossThreadSize: 4  # boss线程 默认=cpu核心数
    workThreadSize: 8  # work线程 默认=cpu核心数*2
    businessThreadSize: 16 # 业务线程数 默认=cpu核心数*10
    businessQueueSize: 100000 #业务队列 默认=100000
L
yaml  
luxurong 已提交
169 170
    lowWaterMark: 4000000 # 不建议配置 默认 32768
    highWaterMark: 80000000 # 不建议配置 默认 65536
L
doc  
luxurong 已提交
171 172 173 174
    options: # netty option设置
      SO_BACKLOG: 200
    childOptions:  #netty child option设置
      SO_REUSEADDR: true
L
yaml  
luxurong 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
    ssl: # ssl配置
      enable: false # 开关
      key: /user/server.key # 指定ssl文件 默认系统生成
      crt: /user/server.crt # 指定ssl文件 默认系统生成
  http: # http相关配置 端口固定60000
    enable: true # 开关
    accessLog: true # http访问日志
    ssl: # ssl配置
      enable: false
    admin: # 后台管理配置
      enable: true  # 开关
      username: smqtt # 访问用户名
      password: smqtt # 访问密码
  ws: # websocket配置
    enable: true # 开关
    port: 8999 # 端口
    path: /mqtt # ws 的访问path mqtt.js请设置此选项
  cluster: # 集群配置
    enable: false # 集群开关
    url: 127.0.0.1:7771,127.0.0.1:7772 # 启动节点
    port: 7771  # 端口
    node: node-1 # 集群节点名称 唯一
L
doc  
luxurong 已提交
197
    namespace: smqtt
L
yaml  
luxurong 已提交
198 199 200
    external:
      host: localhost # 用于映射容器ip 请不要随意设置,如果不需要请移除此选项
      port: 7777 # 用于映射容器端口 请不要随意设置,如果不需要请移除此选项
L
doc  
luxurong 已提交
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
  db: # 数据库相关设置 请参考 https://doc.smqtt.cc/%E5%85%B6%E4%BB%96/1.store.html 【如果没有引入相关依赖请移除此配置】
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/smqtt?characterEncoding=utf-8&useSSL=false&useInformationSchema=true&serverTimezone=UTC
    username: root
    password: 123
    initialSize: 10
    maxActive: 300
    maxWait: 60000
    minIdle: 2
  redis: # redis 请参考 https://doc.smqtt.cc/%E5%85%B6%E4%BB%96/1.store.html 【如果没有引入相关依赖请移除此配置】
    mode: single
    database: 0
    password:
    timeout: 3000
    poolMinIdle: 8
    poolConnTimeout: 3000
    poolSize: 10
    single:
      address: 127.0.0.1:6379
    cluster:
      scanInterval: 1000
      nodes: 127.0.0.1:7000,127.0.0.1:7001,127.0.0.1:7002,127.0.0.1:7003,127.0.0.1:7004,127.0.0.1:7005
      readMode: SLAVE
      retryAttempts: 3
      slaveConnectionPoolSize: 64
      masterConnectionPoolSize: 64
      retryInterval: 1500
    sentinel:
      master: mymaster
      nodes: 127.0.0.1:26379,127.0.0.1:26379,127.0.0.1:26379

L
luxurong 已提交
232 233
  ```

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

L
luxurong 已提交
236
```markdown
L
yaml  
luxurong 已提交
237
  java -jar smqtt-bootstrap-1.0.1-SNAPSHOT.jar <config.yaml路径>
L
luxurong 已提交
238
```
L
luxurong 已提交
239 240 241



L
luxurong 已提交
242
## docker 方式
L
luxurong 已提交
243

L
luxurong 已提交
244 245

拉取镜像
L
luxurong 已提交
246 247

``` 
L
luxurong 已提交
248
# 拉取docker镜像地址
L
luxurong 已提交
249 250 251
docker pull 1ssqq1lxr/smqtt:latest
```

L
luxurong 已提交
252
启动镜像默认配置
L
luxurong 已提交
253 254

``` 
L
luxurong 已提交
255
# 启动服务
L
luxurong 已提交
256 257 258
docker run -it  -p 1883:1883 1ssqq1lxr/smqtt
```

1
1091927336@qq.com 已提交
259
启动镜像使用自定义配置(同上准备配置文件config.yaml)
L
luxurong 已提交
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276


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

1ssqq1lxr's avatar
1ssqq1lxr 已提交
279 280 281 282 283 284 285
## 管理后台(60000端口)

### 如何开启

    
- main启动
    
L
luxurong 已提交
286
    1. 初始化BootstrapConfig.HttpConfig对象
1ssqq1lxr's avatar
1ssqq1lxr 已提交
287
    ``` 
L
luxurong 已提交
288 289 290 291 292 293
     BootstrapConfig
             .HttpConfig
             .builder()
             .enable(true)
             .accessLog(true)
             .build()
1ssqq1lxr's avatar
1ssqq1lxr 已提交
294
    ```
L
luxurong 已提交
295 296 297 298
    2. 设置到Bootstrap中
      ``` 
        Bootstrap.builder().httpConfig(你的HttpConfig);
      ```      
1ssqq1lxr's avatar
1ssqq1lxr 已提交
299 300
- jar / docker 启动
    
L
yaml  
luxurong 已提交
301
   设置config.yaml
1ssqq1lxr's avatar
1ssqq1lxr 已提交
302 303
   
    ``` 
L
yaml  
luxurong 已提交
304 305 306 307 308 309 310 311 312 313
    smqtt:
      http: # http相关配置 端口固定60000
        enable: true # 开关
        accessLog: true # http访问日志
        ssl: # ssl配置
          enable: false
        admin: # 后台管理配置
          enable: true  # 开关
          username: smqtt # 访问用户名
          password: smqtt # 访问密码
1ssqq1lxr's avatar
1ssqq1lxr 已提交
314
    ```
L
luxurong 已提交
315 316
  
> 访问路径  http是://127.0.0.1:60000/smqtt/admin
1ssqq1lxr's avatar
1ssqq1lxr 已提交
317 318 319 320

### 页面预览

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

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

L
luxurong 已提交
325
## wiki地址
L
luxurong 已提交
326

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

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

L
version  
luxurong 已提交
331

L
luxurong 已提交
332
## License
L
luxurong 已提交
333

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

L
luxurong 已提交
336

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

1ssqq1lxr's avatar
pages  
1ssqq1lxr 已提交
340 341 342 343
- 添加微信号`Lemon877164954`,拉入smqtt官方交流群
- 加入qq群 `700152283`