标签:ons pen roo top ror auth read red img
SMQTT基于Netty开发,底层采用Reactor3反应堆模型,支持单机部署,支持容器化部署,具备低延迟,高吞吐量,支持百万TCP连接,同时支持多种协议交互,是一款非常优秀的消息中间件!
引入依赖
<dependency>
<groupId>io.github.quickmsg</groupId>
<artifactId>smqtt-core</artifactId>
<version>1.0.6</version>
</dependency>
阻塞式启动服务:
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();
非阻塞式启动服务:
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();
在smqtt-bootstrap/target目录下生成jar
# 日志级别 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
# 容器集群映射主机
# smqtt.cluster.external.host = localhost
# 容器集群映射port
# smqtt.cluster.external.port
java -jar smqtt-bootstrap-1.0.1-SNAPSHOT.jar <conf.properties路径>
拉取镜像
# 拉取docker镜像地址
docker pull 1ssqq1lxr/smqtt:latest
启动镜像默认配置
# 启动服务
docker run -it -p 1883:1883 1ssqq1lxr/smqtt
启动镜像使用自定义配置(同上准备配置文件conf.properties)
# 启动服务
docker run -it -v <配置文件路径目录>:/conf -p 1883:1883 -p 1999:1999 1ssqq1lxr/smqtt
启动客户端订阅主题 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"
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
集群类配置参考文档:
全网唯一开源java开发的支持高扩展,高性能的Mqtt集群broker!
标签:ons pen roo top ror auth read red img
原文地址:https://www.cnblogs.com/1ssqq1lxr/p/15006827.html