Skip to content

Commit

Permalink
Using MQTTClient. There is no reason to use MQTTAsyncClient.
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianromero committed Aug 3, 2019
1 parent 1090a7d commit 72d5f23
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/adr/helloiot/mqtt/ManagerMQTT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,7 +68,7 @@ public class ManagerMQTT implements MqttCallback, ManagerProtocol {
private Consumer<EventMessage> consumer;
private Consumer<Throwable> lost;
// MQTT
private MqttAsyncClient mqttClient;
private MqttClient mqttClient;
private final List<String> worktopics = new ArrayList<>();
private final List<Integer> workqos = new ArrayList<>();
private final ResourceBundle resources;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 72d5f23

Please # to comment.