Commit 2a56b716 authored by René Schöne's avatar René Schöne
Browse files

First real test using MQTT to send and receive messages.

- also try to setup CI (might fail)
parent 81c1b10c
...@@ -145,16 +145,18 @@ public class MqttUpdater { ...@@ -145,16 +145,18 @@ public class MqttUpdater {
// subscribe at broker // subscribe at broker
org.fusesource.mqtt.client.Topic[] topicArray = { new org.fusesource.mqtt.client.Topic(topic, this.qos) }; org.fusesource.mqtt.client.Topic[] topicArray = { new org.fusesource.mqtt.client.Topic(topic, this.qos) };
connection.subscribe(topicArray, new org.fusesource.mqtt.client.Callback<byte[]>() { connection.getDispatchQueue().execute(() -> {
@Override connection.subscribe(topicArray, new org.fusesource.mqtt.client.Callback<byte[]>() {
public void onSuccess(byte[] qoses) { @Override
logger.debug("Subscribed to {}, qoses: {}", topic, qoses); public void onSuccess(byte[] qoses) {
} logger.debug("Subscribed to {}, qoses: {}", topic, qoses);
}
@Override @Override
public void onFailure(Throwable cause) { public void onFailure(Throwable cause) {
logger.error("Could not subscribe to {}", topic, cause); logger.error("Could not subscribe to {}", topic, cause);
} }
});
}); });
} }
...@@ -187,30 +189,34 @@ public class MqttUpdater { ...@@ -187,30 +189,34 @@ public class MqttUpdater {
logger.warn("Stopping without connection. Was setHost() called?"); logger.warn("Stopping without connection. Was setHost() called?");
return; return;
} }
connection.disconnect(new org.fusesource.mqtt.client.Callback<Void>() { connection.getDispatchQueue().execute(() -> {
@Override connection.disconnect(new org.fusesource.mqtt.client.Callback<Void>() {
public void onSuccess(Void value) { @Override
logger.info("Disconnected {} from {}", name, host); public void onSuccess(Void value) {
} logger.info("Disconnected {} from {}", name, host);
}
@Override @Override
public void onFailure(Throwable ignored) { public void onFailure(Throwable ignored) {
// Disconnects never fail. And we do not care either. // Disconnects never fail. And we do not care either.
} }
});
}); });
} }
public void publish(String topic, byte[] bytes) { public void publish(String topic, byte[] bytes) {
connection.publish(topic, bytes, qos, false, new org.fusesource.mqtt.client.Callback<Void>() { connection.getDispatchQueue().execute(() -> {
@Override connection.publish(topic, bytes, qos, false, new org.fusesource.mqtt.client.Callback<Void>() {
public void onSuccess(Void value) { @Override
logger.debug("Published some bytes to {}", topic); public void onSuccess(Void value) {
} logger.debug("Published some bytes to {}", topic);
}
@Override @Override
public void onFailure(Throwable value) { public void onFailure(Throwable value) {
logger.warn("Could not publish on topic '{}'", topic); logger.warn("Could not publish on topic '{}'", topic);
} }
});
}); });
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment