当前位置:网站首页>Mqtt disconnect and reconnect
Mqtt disconnect and reconnect
2022-06-26 11:16:00 【Enlarged EZ】
problem
Recent development projects require MQTT, When the development completes the test, it is often found that the connection is disconnected .
There is no error message , In the omnipotent Baidu search to see if there are any netizens who have encountered the same problem , It turns out that it may be the client ID The problem of , I start the same client every time ID, Previous clients ID stay MQTT The server is still stored and not cleaned up , If you start the client again, you will not be able to connect .
resolvent
Use random numbers to survive clients ID, Restart , Problem solved , Not always connected and disconnected .
The project has been running for several days and a new problem is found , If there is no operation for a long time, the connection will still be disconnected , Unable to send and receive messages .
Check it online MQTT Related articles , Learn more about MQTT, Find out MQTT There is an automatic reconnection function . There are two ways to achieve automatic reconnection .
1、MQTT Connection configuration class MqttConnectOption Class can set automatic reconnection . Here's the picture :

After setting automatic reconnection ,callback To achieve MqttCallbackExtended, There is a callback method for connection completion in this interface connectComplete(boolean reconnect,String serverURI), After the connection is completed, you can subscribe to the topic . Here's the picture :

2、 Custom reconnection
If MQTT Connection configuration class MqttConnectOption Class does not configure automatic reconnection , You can also do custom reconnection .MqttCallback There is a in the interface connectionLost(Throwable arg0) Interface , You can customize reconnection in the implementation method of this interface . Here's the picture :

summary
That's about MQTT Some problems of disconnection and reconnection , I hope I can help you .
Reprint of the article :
边栏推荐
- APICloud 实现文档下载和预览功能
- Is it safe to open a stock account by mobile phone
- 统计遗传学:第一章,基因组基础概念
- 最强swarm集群一键部署+氢弹级容器管理工具介绍
- 19: Chapter 3: develop pass service: 2: get through Alibaba cloud SMS service in the program; (it only connects with Alibaba cloud SMS server, and does not involve specific business development)
- flannel的host-gw与calico
- Machine learning LDA - Experimental Report
- Redis的最佳实践?看完不心动,算我输!!
- 深度理解STM32的串口實驗(寄存器)【保姆級教程】
- Compréhension approfondie de l'expérience de port série stm32 (registre) [Tutoriel de niveau nounou]
猜你喜欢

sliding window

机器学习线性回归——实验报告

Machine learning PCA - Experimental Report

April 13, 2021 interview with beaver family

FastRCNN

有手就行的移动平均法、指数平滑法的Excel操作,用来时间序列预测

18: Chapter 3: development of pass service: 1: SMS login & registration process, introduction; (SMS verification code is used here)

FasterRCNN

Cet article présente la moyenne mobile quadratique linéaire et le fonctionnement simple d'Excel pour réaliser la prédiction des séries chronologiques dans la modélisation.

C language -- operators and expressions
随机推荐
c语言 --- 运算符和表达式
MySQL performance monitoring and SQL statements
统计遗传学:第二章,统计分析概念
Fabric. JS upper dash, middle dash (strikethrough), underline
即构「畅直播」上线!提供全链路升级的一站式直播服务
19: Chapter 3: develop pass service: 2: get through Alibaba cloud SMS service in the program; (it only connects with Alibaba cloud SMS server, and does not involve specific business development)
深圳市福田区支持文化创意产业发展若干措施
[deep learning theory] (7) long and short term memory network LSTM
Machine Learning Clustering - Experimental Report
Laravel-admin 登录添加图形验证码
laravel中使用group by分组并查询数量
介紹一下實現建模中可能用到的時間序列預測之線性二次移動平均,Excel的簡單操作
24 个必须掌握的数据库面试问题!
FastRCNN
Sqli labs range 1-5
(Typora图床)阿里云oss搭建图床+Picgo上传图片详细教程
MySQL 30 military regulations
FastRCNN
服务器单、双向可调一键互信脚本!
April 13, 2021 interview with beaver family