Skip to content

Commit

Permalink
Fix topic subscriptions QOS
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu committed Apr 20, 2024
1 parent 1e29842 commit 954b0fc
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ private void connectAndSetupMqtt() {
mqttClient.connect(mqttConnectOptions);
attachedClients.clear();
attachedClients.add(deviceId);
subscribeToUpdates(deviceId);
subscribeToConfig(deviceId);
subscribeToErrors(deviceId);
subscribeToCommands(deviceId);
LOG.info(deviceId + " done with setup connection");
Expand Down Expand Up @@ -471,26 +471,26 @@ private String getMessageTopic(String deviceId, String topic) {
return topicBase + format(MESSAGE_TOPIC_FMT, topic);
}

private void subscribeToUpdates(String deviceId) {
clientSubscribe(CONFIG_TOPIC, QOS_AT_MOST_ONCE);
private void subscribeToConfig(String deviceId) {
clientSubscribe(CONFIG_TOPIC, QOS_AT_LEAST_ONCE);
}

private void clientSubscribe(String topicSuffix, int qos) {
String topic = topicBase + topicSuffix;
try {
LOG.info("Subscribed to mqtt topic " + topic);
LOG.info(format("Subscribing with qos %d to topic %s", qos, topic));
mqttClient.subscribe(topic, qos);
} catch (MqttException e) {
throw new RuntimeException("While subscribing to MQTT topic " + topic, e);
}
}

private void subscribeToErrors(String deviceId) {
clientSubscribe(ERROR_TOPIC, QOS_AT_MOST_ONCE);
clientSubscribe(ERROR_TOPIC, QOS_AT_LEAST_ONCE);
}

private void subscribeToCommands(String deviceId) {
clientSubscribe(COMMAND_TOPIC, QOS_AT_LEAST_ONCE);
clientSubscribe(COMMAND_TOPIC, QOS_AT_MOST_ONCE);
}

String getDeviceId() {
Expand Down

0 comments on commit 954b0fc

Please sign in to comment.