Open ChunMengLu opened 3 years ago
"before close server:127.0.0.1:1883, client:192.168.10.63:61594, after closeserver:127.0.0.1:1883, client:$UNKNOWN:"为什么这里表示client unknown, 我的yaml肯定没有问题我使用的是emqx, 还有就是我之前使用mosquitto的时候“2024-05-03 15:26:45 [tio-worker-2] INFO org.tio.core. task. CloseRunnable
"before close server:127.0.0.1:1883, client:192.168.10.63:61594, after closeserver:127.0.0.1:1883, client:$UNKNOWN:"为什么这里表示client unknown, 我的yaml肯定没有问题我使用的是emqx, 还有就是我之前使用mosquitto的时候“2024-05-03 15:26:45 [tio-worker-2] INFO org.tio.core. task. CloseRunnable
- TioClientConfig [name=Mica-Mqtt-CLient],server:mosquitto:1883,client:172.18.0.5:35542 准备关闭连接, isNeedRemove: false,对方关闭了连接 2024-05-03 15:26:45 [tio-worker-2] INFO org.tio.core.ChannelContext
- 关闭前server:mosquitto:1883,client:172.18.0.5:35542,关闭后server:mosquitto:1883,cljent:$UNKNOWN:52”
unknown 表示释放 ip 配置了,将 192.168.10.63:61594 配置成了 unknown
1、mica-mqtt-spring-boot-starter 空指针 NullPointerException
详细信息: Mqtt server IMqttMessageListener Bean not found
解决方案:IMqttMessageListener 为业务处理,必须要实现的接口。实现该接口并注册成 Spring Bean 即可。
2、解码异常
-Dtio.default.read.buffer.size=1048576
(1M,也就是最大支持 10M 消息体,请按需设置)。useQueueDecode(true)
1.3.7 会默认成 true。不过业务一直处理不赢还是会照成更严重的问题。最后队列占满导致 jvm 内存溢出。建议集群并对接 kafka、rocketmq 等。3、NoSuchMethodError: java.nio.ByteBuffer.XXX(I)Ljava/nio/ByteBuffer;
存在此问题的版本:
1.0.0
、1.0.0-RC
、1.0.3
、1.0.4
该问题主要是 jar 编译问题,由于 JDK9+ 改了 ByteBuffer 部分返回值的类型,导致 java9+ 下编译的 jar 在 java8 下运行会有问题。如果遇到此问题,请立刻反馈。4、多个客户端使用相同 clientId 导致前者被踢下线
IMqttServerUniqueIdService
(1.1.4开始支持) 接口,返回的uniqueId
会替代 clientId,后续的场景也是需要使用这个uniqueId
来处理。5、nginx tcp 负载均衡
5.1 搜索关键词
nginx tcp 负载均衡
即可:5.2 配置 /etc/nginx/nginx.conf,示例:
6、Mqtt 集群
mica-mqtt 1.1.2 版本开始添加了
mica-mqtt-broker
模块,采用 redis pub/sub 实现集群,有需求的朋友可以参考。7、SNAPSHOT 版本使用
snapshots 版本会及时响应修复最新的 bug 和需求。
SNAPSHOT 版本使用参考这里:https://www.dreamlu.net/mica2x/#%E4%BD%BF%E7%94%A8-snapshots
8、ssl 证书
8.1 申请的证书
腾讯云、阿里云等提供有 jks 证书,直接申请下载,记住申请时的密码: 代码中
.useSsl("classpath:xxx.jks", "classpath:xxx.jks", "密码")
即可8.2 自签证书(双向认证)
server-cert.pem
、server-key.pem
在线转换成 jks 证书(注意,第一步1生成的时候它是没有设置私钥密码,这里不用设置,新文件密码就是 mqtt server 中要用的密码):https://myssl.com/cert_convert.html.useSsl("classpath:xxx.jks", "classpath:xxx.jks", "密码")
开启 ssl。更多教程:openssl自签名证书教程(单域名证书/泛域名证书/多域名证书)详见:https://www.orcy.net.cn/340.html
9、服务器配置调优
详见: Linux 操作系统参数和TCP 协议栈网络参数章节
10、Mqtt client 动态更新 clientId,username,password
11、浏览器 mqtt.js websocket 连接
科普:浏览器只能走 websocket mqtt 子协议,对应 mica-mqtt 8083 端口。
连错端口会报异常,如下:
mqtt.js websocket 示例:
十二、mqtt 心跳超时
拔网线等非正常断开需要一个心跳检测周期才会触发断开。
十三、client、server 同时使用时 caffeine 依赖异常
解决方案: pom 中将 mqtt server 依赖放 mqtt client 前面。