diff --git a/netty-mqtt/src/main/java/org/thingsboard/mqtt/MqttHandler.java b/netty-mqtt/src/main/java/org/thingsboard/mqtt/MqttHandler.java index 21c07a17cd..5bd249ff5c 100644 --- a/netty-mqtt/src/main/java/org/thingsboard/mqtt/MqttHandler.java +++ b/netty-mqtt/src/main/java/org/thingsboard/mqtt/MqttHandler.java @@ -15,10 +15,30 @@ */ package org.thingsboard.mqtt; -import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.Future; import io.netty.buffer.ByteBuf; public interface MqttHandler { - - ListenableFuture onMessage(String topic, ByteBuf payload); + /** + * Changing ListenableFuture to Future allows you to choose CompletableFuture, + * which gives developers the freedom to choose the orchestration method. + * CompletableFuture is a newer, more evolved version that eliminates callback hell, + * is easier to use, and comes with the JDK. jdk 1.8 was previously used with the Before JDK1.8, + * use ListenableFuture, after that, it is recommended to use CompletableFuture. + * ListenableFuture It's still written that way.{@link MqttMessageListener#onMessage(topic, payload)} + * public ListenableFuture onMessage(String topic, ByteBuf message) { + * log.info("MQTT message [{}], topic [{}]", message.toString(StandardCharsets.UTF_8), topic); + * events.add(new MqttEvent(topic, message.toString(StandardCharsets.UTF_8))); + * return Futures.immediateVoidFuture(); + * } + * CompletableFuture It's like this. + * public CompletableFuture onMessage(String topic, ByteBuf message) { + * log.info("MQTT message [{}], topic [{}]", message.toString(StandardCharsets.UTF_8), topic); + * events.add(new MqttEvent(topic, message.toString(StandardCharsets.UTF_8))); + * return CompletableFuture.completedFuture(null); + * } + * This change does not affect the system's current use of ListenableFuture so that it is free to choose between ListenableFuture or + * CompletableFuture in new development. + */ + Future onMessage(String topic, ByteBuf payload); }