Browse Source

mqtt连接超时处理

develop
lau572 4 months ago
parent
commit
e8c2c6d594
  1. 34
      zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java

34
zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java

@ -277,19 +277,29 @@ public class NonAutomaticWarningController extends BaseController {
}); });
// 建立连接 // 建立连接
logger.info("连接到 broker: " + host); try {
client.connect(options); logger.info("连接到 broker: " + host);
client.connect(options);
logger.info("连接成功."); logger.info("连接成功.");
//订阅消息 //订阅消息
//client.subscribe(topicName.getString("6274883585"), 1); //client.subscribe(topicName.getString("6274883585"), 1);
//logger.info("开始监听" + topicName.getString("6274883585")); //logger.info("开始监听" + topicName.getString("6274883585"));
client.subscribe(topicName.getString("6274879489"), UniversalEnum.ONE.getNumber()); client.subscribe(topicName.getString("6274879489"), UniversalEnum.ONE.getNumber());
logger.info("开始监听" + topicName.getString("6274879489")); logger.info("开始监听" + topicName.getString("6274879489"));
//client.subscribe(topicName.getString("7768236033"), 1); //client.subscribe(topicName.getString("7768236033"), 1);
//logger.info("开始监听" + topicName.getString("7768236033")); //logger.info("开始监听" + topicName.getString("7768236033"));
//client.subscribe(topicName.getString("7835340801"), 1); //client.subscribe(topicName.getString("7835340801"), 1);
//logger.info("开始监听" + topicName.getString("7835340801")); //logger.info("开始监听" + topicName.getString("7835340801"));
} catch (MqttException e) {
if (e.getReasonCode() == MqttException.REASON_CODE_CLIENT_TIMEOUT) {
logger.warn("连接超时.");
// 尝试重连
getAjaxResult(parameter);
} else {
throw e; // 抛出其他类型的异常
}
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

Loading…
Cancel
Save