Bug概述
- 服务端、客户端通信使用MQTT
- 客户端发生 小概率偶现 无法收到服务端Message,而后端显示已发送
Bug排查结果
- 客户端的MqttAndroidClient使用的ClientId因后端 没给值,导致ClientId为空 — 让后端解决
- 客户端没有断线重连机制,不要听信部分地方说的 在MqttCallbackExtended的connectionLost方法中写connect方法,这是错误的,有更好的,用MqttConnectOptions的setAutomaticReconnect方法 — 客户端解决
- Android客户端的MqttAndroidClient 执行connect存在,无法释放的情况,具体是Service的onDestory中写了disconnect,在onStartCommand中写了connect,这不对称,改至onCreate — 客户端解决
- 解决上一条,正因为有上一条,结合MqttConnectOptions的setCleanSession方法的描述(见下面的说明),将setCleanSession设置为true解决 — 客户端解决
/**
<ul><li>Sets whether the client and server should remember state across restarts and reconnects.</li>
<li><ul></li>
<li><li>If set to false both the client and server will maintain state across</li>
<li>restarts of the client, the server and the connection. As state is maintained:</li>

本文记录了一次关于MQTT协议的bug,主要表现为Android客户端小概率收不到服务端消息。经过排查,问题出在:1) 客户端ClientId为空;2) 缺少断线重连机制;3) MqttAndroidClient connect/disconnect操作不当;4) MqttConnectOptions的setCleanSession设置。通过相应改进,成功解决了问题。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



