[mqtt] Only unsubscribe if we subscribed before (#9758)
Fix for 9730 Signed-off-by: Jochen Klein <git@jochen.susca.de>
This commit is contained in:
parent
79b94e3e34
commit
b6eea715fa
@ -53,8 +53,9 @@ public class TopicSubscribe implements MqttMessageSubscriber {
|
|||||||
@Override
|
@Override
|
||||||
public void processMessage(String topic, byte[] payload) {
|
public void processMessage(String topic, byte[] payload) {
|
||||||
final MqttBrokerConnection connection = this.connection;
|
final MqttBrokerConnection connection = this.connection;
|
||||||
if (connection == null)
|
if (connection == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if (payload.length > 0) {
|
if (payload.length > 0) {
|
||||||
topicDiscoveredListener.receivedMessage(thing, connection, topic, payload);
|
topicDiscoveredListener.receivedMessage(thing, connection, topic, payload);
|
||||||
} else {
|
} else {
|
||||||
@ -80,7 +81,8 @@ public class TopicSubscribe implements MqttMessageSubscriber {
|
|||||||
* @return Completes with true if successful. Exceptionally otherwise.
|
* @return Completes with true if successful. Exceptionally otherwise.
|
||||||
*/
|
*/
|
||||||
public CompletableFuture<Boolean> stop() {
|
public CompletableFuture<Boolean> stop() {
|
||||||
CompletableFuture<Boolean> stopFuture = connection == null ? CompletableFuture.completedFuture(true)
|
CompletableFuture<Boolean> stopFuture = connection == null || !isStarted
|
||||||
|
? CompletableFuture.completedFuture(true)
|
||||||
: connection.unsubscribe(topic, this);
|
: connection.unsubscribe(topic, this);
|
||||||
isStarted = false;
|
isStarted = false;
|
||||||
return stopFuture;
|
return stopFuture;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user