diff --git a/src/main/java/com/icaroerasmo/config/DtTMqttCallBack.java b/src/main/java/com/icaroerasmo/config/DtTMqttCallBack.java deleted file mode 100644 index dd7108e..0000000 --- a/src/main/java/com/icaroerasmo/config/DtTMqttCallBack.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.icaroerasmo.config; - -import lombok.RequiredArgsConstructor; -import lombok.extern.log4j.Log4j2; -import org.eclipse.paho.client.mqttv3.*; - -import java.util.List; - -@Log4j2 -@RequiredArgsConstructor -public class DtTMqttCallBack implements MqttCallbackExtended { - - private final IMqttClient client; - private final List topics; - - @Override - public void connectComplete(boolean b, String s) { - topics.forEach(t -> { - try { - this.client.subscribe(t, 0); - } catch (MqttException e) { - throw new RuntimeException(e); - } - }); - } - - @Override - public void connectionLost(Throwable throwable) { - - } - - @Override - public void messageArrived(String s, MqttMessage mqttMessage) throws Exception { - log.info(String.format("[%s] %s", s, new String(mqttMessage.getPayload()))); - } - - @Override - public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) { - - } -} diff --git a/src/main/java/com/icaroerasmo/config/MqttConfig.java b/src/main/java/com/icaroerasmo/config/MqttConfig.java index 00dd556..83d8324 100644 --- a/src/main/java/com/icaroerasmo/config/MqttConfig.java +++ b/src/main/java/com/icaroerasmo/config/MqttConfig.java @@ -57,15 +57,9 @@ public IMqttClient mqttClient() throws MqttException { } @Bean - @DependsOn({"mqttClient", "registerListeners"}) + @DependsOn({"registerListeners"}) public Void listen(IMqttClient mqttClient, List listeners) { - - DtTMqttCallBack callBack = new DtTMqttCallBack(mqttClient, - listeners.stream().map(AbstractListener::getTopic).toList()); - - listeners.forEach(listener -> listener.listen()); - mqttClient.setCallback(callBack); - + listeners.forEach(AbstractListener::listen); return null; }