|
@@ -287,7 +287,7 @@ public class PublishClient {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static void reconnect() throws MqttException {
|
|
|
|
|
|
+ public void reconnect() throws MqttException {
|
|
log.error("尝试重连...");
|
|
log.error("尝试重连...");
|
|
if (client != null) {
|
|
if (client != null) {
|
|
try {
|
|
try {
|
|
@@ -299,17 +299,25 @@ public class PublishClient {
|
|
|
|
|
|
MqttConnectOptions options = new MqttConnectOptions();
|
|
MqttConnectOptions options = new MqttConnectOptions();
|
|
options.setCleanSession(true);
|
|
options.setCleanSession(true);
|
|
- options.setUserName(USER_NAME);
|
|
|
|
- options.setPassword(PASS_WORD.toCharArray());
|
|
|
|
|
|
+ options.setUserName("camera-update");
|
|
|
|
+ options.setPassword("05J5+mtYzx.Ry".toCharArray());
|
|
options.setConnectionTimeout(60);
|
|
options.setConnectionTimeout(60);
|
|
options.setKeepAliveInterval(40);
|
|
options.setKeepAliveInterval(40);
|
|
|
|
|
|
- client = new MqttClient(HOST, String.valueOf(clientId), new MemoryPersistence());
|
|
|
|
- client.setCallback(new PublishCallback());
|
|
|
|
- client.connect(options);
|
|
|
|
- int[] Qos = {1};
|
|
|
|
- String[] topics = {"config", "update", "heart", "test"};
|
|
|
|
- client.subscribe(topics, Qos);
|
|
|
|
|
|
+ try {
|
|
|
|
+ /**
|
|
|
|
+ * 设置发布回调
|
|
|
|
+ */
|
|
|
|
+ client = new MqttClient("tcp://10.161.12.60:1883", "HAZARD-CAMERA-CLIENTID-123", new MemoryPersistence());
|
|
|
|
+
|
|
|
|
+ client.setCallback(new PublishCallback());
|
|
|
|
+ client.connect(options);
|
|
|
|
+ String[] topic1 = {"config", "update", "heart", "test"};
|
|
|
|
+ client.subscribe(topic1);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(e.getMessage());
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
log.error("重连成功!");
|
|
log.error("重连成功!");
|
|
}
|
|
}
|
|
}
|
|
}
|