Fix MQTT transport deprecations (#8570)
Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
@@ -63,9 +63,9 @@ public class MQTTActions implements ThingActions, IMQTTActions {
|
||||
@Override
|
||||
@RuleAction(label = "@text/actionLabel", description = "@text/actionDesc")
|
||||
public void publishMQTT(
|
||||
@ActionInput(name = "topic", label = "@text/actionInputTopicLabel", description = "@text/actionInputTopicDesc") @Nullable String topic,
|
||||
@ActionInput(name = "value", label = "@text/actionInputValueLabel", description = "@text/actionInputValueDesc") @Nullable String value,
|
||||
@ActionInput(name = "retain", label = "@text/actionInputRetainlabel", description = "@text/actionInputRetainDesc") @Nullable Boolean retain) {
|
||||
@ActionInput(name = "topic", label = "@text/actionInputTopicLabel", description = "@text/actionInputTopicDesc") @Nullable final String topic,
|
||||
@ActionInput(name = "value", label = "@text/actionInputValueLabel", description = "@text/actionInputValueDesc") @Nullable final String value,
|
||||
@ActionInput(name = "retain", label = "@text/actionInputRetainlabel", description = "@text/actionInputRetainDesc") @Nullable final Boolean retain) {
|
||||
AbstractBrokerHandler brokerHandler = handler;
|
||||
if (brokerHandler == null) {
|
||||
logger.warn("MQTT Action service ThingHandler is null!");
|
||||
@@ -84,15 +84,14 @@ public class MQTTActions implements ThingActions, IMQTTActions {
|
||||
logger.debug("skipping MQTT publishing of value '{}' as topic is null.", value);
|
||||
return;
|
||||
}
|
||||
if (retain == null) {
|
||||
retain = connection.isRetain();
|
||||
}
|
||||
connection.publish(topic, value.getBytes(), connection.getQos(), retain).thenRun(() -> {
|
||||
logger.debug("MQTT publish to {} performed", topic);
|
||||
}).exceptionally(e -> {
|
||||
logger.warn("MQTT publish to {} failed!", topic);
|
||||
return null;
|
||||
});
|
||||
|
||||
connection.publish(topic, value.getBytes(), connection.getQos(), retain != null && retain.booleanValue())
|
||||
.thenRun(() -> {
|
||||
logger.debug("MQTT publish to {} performed", topic);
|
||||
}).exceptionally(e -> {
|
||||
logger.warn("MQTT publish to {} failed!", topic);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public static void publishMQTT(@Nullable ThingActions actions, @Nullable String topic, @Nullable String value) {
|
||||
|
||||
@@ -42,8 +42,10 @@ public interface MQTTTopicDiscoveryService {
|
||||
/**
|
||||
* Publish a message to all connected brokers
|
||||
*
|
||||
* @param topic The topic to publish on
|
||||
* @param payload The message to publish
|
||||
* @param topic The topic
|
||||
* @param payload The message payload
|
||||
* @param qos The quality of service for this message
|
||||
* @param retain Set to true to retain the message on the broker
|
||||
*/
|
||||
void publish(String topic, byte[] payload);
|
||||
void publish(String topic, byte[] payload, int qos, boolean retain);
|
||||
}
|
||||
|
||||
@@ -223,8 +223,6 @@ public class BrokerHandler extends AbstractBrokerHandler implements PinnedCallba
|
||||
connection.setTimeoutExecutor(scheduler, TIMEOUT_DEFAULT);
|
||||
}
|
||||
|
||||
connection.setRetain(config.retainMessages);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@ public class SystemBrokerHandler extends AbstractBrokerHandler implements MqttSe
|
||||
properties.put(PROPERTY_PASSWORD, password);
|
||||
}
|
||||
properties.put(PROPERTY_QOS, String.valueOf(connection.getQos()));
|
||||
properties.put(PROPERTY_RETAIN, String.valueOf(connection.isRetain()));
|
||||
final MqttWillAndTestament lastWill = connection.getLastWill();
|
||||
if (lastWill != null) {
|
||||
properties.put(PROPERTY_LAST_WILL, lastWill.toString());
|
||||
|
||||
@@ -12,7 +12,13 @@
|
||||
*/
|
||||
package org.openhab.binding.mqtt.internal;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -127,10 +133,10 @@ public class MqttBrokerHandlerFactory extends BaseThingHandlerFactory implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(String topic, byte[] payload) {
|
||||
public void publish(String topic, byte[] payload, int qos, boolean retain) {
|
||||
handlers.forEach(handler -> {
|
||||
handler.getConnectionAsync().thenAccept(connection -> {
|
||||
connection.publish(topic, payload);
|
||||
connection.publish(topic, payload, qos, retain);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user