|
@@ -9,6 +9,7 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* ClassName: MqttPushClient
|
|
@@ -46,7 +47,9 @@ public class MqttPushClient {
|
|
|
public void connect(String host, String clientID, String username, String password, int timeout, int keepalive) {
|
|
|
MqttClient client;
|
|
|
try {
|
|
|
- client = new MqttClient(host, clientID, new MemoryPersistence());
|
|
|
+ String clientID1 = clientID + "_msg" + UUID.randomUUID();
|
|
|
+ System.out.println("当前客户的mqttId是:" + clientID1);
|
|
|
+ client = new MqttClient(host, clientID1, new MemoryPersistence());
|
|
|
MqttConnectOptions options = new MqttConnectOptions();
|
|
|
options.setAutomaticReconnect(true);
|
|
|
options.setCleanSession(true);
|
|
@@ -61,11 +64,15 @@ public class MqttPushClient {
|
|
|
public void connectionLost(Throwable throwable) {
|
|
|
// 连接丢失后,一般在这里面进行重连
|
|
|
logger.info("连接断开,可以做重连");
|
|
|
-// try {
|
|
|
-// client.connect(options);
|
|
|
-// } catch (MqttException e) {
|
|
|
-// throw new RuntimeException(e);
|
|
|
-// }
|
|
|
+ try {
|
|
|
+ String clientID2 = clientID + "_msg" + UUID.randomUUID();
|
|
|
+ System.out.println("当前客户的mqttId是:" + clientID2);
|
|
|
+ MqttClient client2 = new MqttClient(host, clientID, new MemoryPersistence());
|
|
|
+ MqttPushClient.setClient(client2);
|
|
|
+ client2.connect(options);
|
|
|
+ } catch (MqttException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|