From 72d5f23d857beb660910dbe87098863ed76e7ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Romero?= Date: Sat, 3 Aug 2019 18:22:26 +0200 Subject: [PATCH] Using MQTTClient. There is no reason to use MQTTAsyncClient. --- src/main/java/com/adr/helloiot/mqtt/ManagerMQTT.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/adr/helloiot/mqtt/ManagerMQTT.java b/src/main/java/com/adr/helloiot/mqtt/ManagerMQTT.java index 56ac8ea..db91c63 100644 --- a/src/main/java/com/adr/helloiot/mqtt/ManagerMQTT.java +++ b/src/main/java/com/adr/helloiot/mqtt/ManagerMQTT.java @@ -36,8 +36,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; -import org.eclipse.paho.client.mqttv3.MqttAsyncClient; import org.eclipse.paho.client.mqttv3.MqttCallback; +import org.eclipse.paho.client.mqttv3.MqttClient; import org.eclipse.paho.client.mqttv3.MqttConnectOptions; import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttMessage; @@ -68,7 +68,7 @@ public class ManagerMQTT implements MqttCallback, ManagerProtocol { private Consumer consumer; private Consumer lost; // MQTT - private MqttAsyncClient mqttClient; + private MqttClient mqttClient; private final List worktopics = new ArrayList<>(); private final List workqos = new ArrayList<>(); private final ResourceBundle resources; @@ -135,7 +135,7 @@ public void connect() { } try { - mqttClient = new MqttAsyncClient(url, clientid, new MemoryPersistence()); + mqttClient = new MqttClient(url, clientid, new MemoryPersistence()); MqttConnectOptions options = new MqttConnectOptions(); if (!Strings.isNullOrEmpty(username)) { options.setUserName(username); @@ -149,7 +149,7 @@ public void connect() { options.setMaxInflight(maxinflight); options.setSSLProperties(sslproperties); options.setWill(topicsys + "app/" + clientid, new StringFormatSwitch().devalue(MiniVarBoolean.FALSE), 0, true); - mqttClient.connect(options).waitForCompletion(1000); + mqttClient.connect(options); mqttClient.setCallback(this); if (listtopics.length > 0) { mqttClient.subscribe(listtopics, listqos); @@ -165,7 +165,7 @@ private void statusPublish(MiniVar value) throws MqttException { MqttMessage mm = new MqttMessage(new StringFormatSwitch().devalue(value)); mm.setQos(0); mm.setRetained(true); - mqttClient.publish(topicsys + "app/" + clientid, mm).waitForCompletion(); + mqttClient.publish(topicsys + "app/" + clientid, mm); } @Override