README.md 6.6 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 8 9 10 11 12

1.  消息质量等级实现(支持qos0,qos1,qos2)
2.  会话消息
3.  保留消息
4.  遗嘱消息
5.  客户端认证
6.  tls加密
L
luxurong 已提交
13 14 15
7.  websocket协议支持
8.  http协议交互
9.  SPI接口扩展支持
L
luxurong 已提交
16 17 18 19 20 21
    - 消息管理接口(会话消息/保留消息管理)
    - 通道管理接口 (管理系统的客户端连接)
    - 认证接口 (用于自定义外部认证)
    - 拦截器  (用户自定义拦截消息)
10. 集群支持(gossip协议实现)
11. 容器化支持 
1ssqq1lxr's avatar
1ssqq1lxr 已提交
22
12. 持久化支持(session 保留消息)
L
luxurong 已提交
23
13. 管理系统
L
luxurong 已提交
24 25 26 27




L
luxurong 已提交
28
## main方式启动
L
luxurong 已提交
29 30 31

引入依赖
```markdown
L
luxurong 已提交
32 33 34
<dependency>
  <groupId>io.github.quickmsg</groupId>
  <artifactId>smqtt-core</artifactId>
L
luxurong 已提交
35
  <version>1.0.6</version>
L
luxurong 已提交
36
</dependency>
L
luxurong 已提交
37 38 39 40 41 42 43

```

阻塞式启动服务:

```markdown

1ssqq1lxr's avatar
1ssqq1lxr 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
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 已提交
68 69 70 71 72 73 74

```

非阻塞式启动服务:

```markdown

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

```


L
luxurong 已提交
104
## jar方式
L
luxurong 已提交
105 106


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

L
luxurong 已提交
109 110 111
```markdown
  在smqtt-bootstrap/target目录下生成jar
```
L
luxurong 已提交
112

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

L
luxurong 已提交
115 116
```markdown
    
1ssqq1lxr's avatar
1ssqq1lxr 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
# 日志级别 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 已提交
165 166 167 168 169
# 容器集群映射主机
# smqtt.cluster.external.host = localhost
# 容器集群映射port
# smqtt.cluster.external.port

L
luxurong 已提交
170

L
luxurong 已提交
171 172
  ```

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

L
luxurong 已提交
175 176 177
```markdown
  java -jar smqtt-bootstrap-1.0.1-SNAPSHOT.jar <conf.properties路径>
```
L
luxurong 已提交
178 179 180



L
luxurong 已提交
181
## docker 方式
L
luxurong 已提交
182

L
luxurong 已提交
183 184

拉取镜像
L
luxurong 已提交
185 186

``` 
L
luxurong 已提交
187
# 拉取docker镜像地址
L
luxurong 已提交
188 189 190
docker pull 1ssqq1lxr/smqtt:latest
```

L
luxurong 已提交
191
启动镜像默认配置
L
luxurong 已提交
192 193

``` 
L
luxurong 已提交
194
# 启动服务
L
luxurong 已提交
195 196 197
docker run -it  -p 1883:1883 1ssqq1lxr/smqtt
```

1ssqq1lxr's avatar
1ssqq1lxr 已提交
198
启动镜像使用自定义配置(同上准备配置文件conf.properties)
L
luxurong 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215


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

1ssqq1lxr's avatar
1ssqq1lxr 已提交
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
## 管理后台(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 已提交
255

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

L
luxurong 已提交
259
## wiki地址
L
luxurong 已提交
260

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

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

L
luxurong 已提交
265

L
luxurong 已提交
266
## License
L
luxurong 已提交
267

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

L
luxurong 已提交
270

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

1ssqq1lxr's avatar
pages  
1ssqq1lxr 已提交
274 275 276 277
- 添加微信号`Lemon877164954`,拉入smqtt官方交流群
- 加入qq群 `700152283`