README.md 9.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协议支持
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>
1ssqq1lxr's avatar
port  
1ssqq1lxr 已提交
61
  <version>${Latest version}</version>
L
luxurong 已提交
62
</dependency>
L
luxurong 已提交
63 64 65 66
<!--集群依赖 -->
<dependency>
   <artifactId>smqtt-registry-scube</artifactId>
   <groupId>io.github.quickmsg</groupId>
1ssqq1lxr's avatar
port  
1ssqq1lxr 已提交
67
   <version>${Latest version}</version>
L
luxurong 已提交
68 69 70 71 72
</dependency>
<!--管理ui依赖 -->
<dependency>
   <artifactId>smqtt-ui</artifactId>
   <groupId>io.github.quickmsg</groupId>
1ssqq1lxr's avatar
port  
1ssqq1lxr 已提交
73
   <version>${Latest version}</version>
L
luxurong 已提交
74
</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

L
yaml  
luxurong 已提交
153
2. 准备配置文件 config.yaml
L
luxurong 已提交
154

L
luxurong 已提交
155
```markdown
L
luxurong 已提交
156

L
yaml  
luxurong 已提交
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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
smqtt:
  logLevel: DEBUG # 系统日志
  tcp: # tcp配置
    port: 1883 # mqtt端口号
    username: smqtt # mqtt连接默认用户名  生产环境建议spi去注入PasswordAuthentication接口
    password: smqtt  # mqtt连接默认密码 生产环境建议spi去注入PasswordAuthentication接口
    wiretap: true  # 二进制日志 前提是 smqtt.logLevel = DEBUG
    bossThreadSize: 4  # boss线程
    workThreadSize: 8  # work线程
    lowWaterMark: 4000000 # 不建议配置 默认 32768
    highWaterMark: 80000000 # 不建议配置 默认 65536
    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 # 集群节点名称 唯一
    external:
      host: localhost # 用于映射容器ip 请不要随意设置,如果不需要请移除此选项
      port: 7777 # 用于映射容器端口 请不要随意设置,如果不需要请移除此选项
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 已提交
224 225
  ```

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

L
luxurong 已提交
228
```markdown
L
yaml  
luxurong 已提交
229
  java -jar smqtt-bootstrap-1.0.1-SNAPSHOT.jar <config.yaml路径>
L
luxurong 已提交
230
```
L
luxurong 已提交
231 232 233



L
luxurong 已提交
234
## docker 方式
L
luxurong 已提交
235

L
luxurong 已提交
236 237

拉取镜像
L
luxurong 已提交
238 239

``` 
L
luxurong 已提交
240
# 拉取docker镜像地址
L
luxurong 已提交
241 242 243
docker pull 1ssqq1lxr/smqtt:latest
```

L
luxurong 已提交
244
启动镜像默认配置
L
luxurong 已提交
245 246

``` 
L
luxurong 已提交
247
# 启动服务
L
luxurong 已提交
248 249 250
docker run -it  -p 1883:1883 1ssqq1lxr/smqtt
```

1ssqq1lxr's avatar
1ssqq1lxr 已提交
251
启动镜像使用自定义配置(同上准备配置文件conf.properties)
L
luxurong 已提交
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268


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

1ssqq1lxr's avatar
1ssqq1lxr 已提交
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
## 管理后台(60000端口)

### 如何开启

    
- main启动
    
   设置httpOptions && enableAdmin = true
   
    ``` 
    Bootstrap.httpOptions(Bootstrap.HttpOptions.builder().enableAdmin(true).ssl(false).accessLog(true).build())
  
    ```
- jar / docker 启动
    
L
yaml  
luxurong 已提交
286
   设置config.yaml
1ssqq1lxr's avatar
1ssqq1lxr 已提交
287 288
   
    ``` 
L
yaml  
luxurong 已提交
289 290 291 292 293 294 295 296 297 298
    smqtt:
      http: # http相关配置 端口固定60000
        enable: true # 开关
        accessLog: true # http访问日志
        ssl: # ssl配置
          enable: false
        admin: # 后台管理配置
          enable: true  # 开关
          username: smqtt # 访问用户名
          password: smqtt # 访问密码
1ssqq1lxr's avatar
1ssqq1lxr 已提交
299 300 301 302 303
    ```

### 页面预览

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

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

L
luxurong 已提交
308
## wiki地址
L
luxurong 已提交
309

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

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

L
version  
luxurong 已提交
314

L
luxurong 已提交
315
## License
L
luxurong 已提交
316

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

L
luxurong 已提交
319

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

1ssqq1lxr's avatar
pages  
1ssqq1lxr 已提交
323 324 325 326
- 添加微信号`Lemon877164954`,拉入smqtt官方交流群
- 加入qq群 `700152283`