diff --git a/nxhs-service/src/main/java/cc/yunxi/config/MqttConfig.java b/nxhs-service/src/main/java/cc/yunxi/config/MqttConfig.java deleted file mode 100644 index 29538fc..0000000 --- a/nxhs-service/src/main/java/cc/yunxi/config/MqttConfig.java +++ /dev/null @@ -1,30 +0,0 @@ -package cc.yunxi.config; - -import cc.yunxi.config.props.MqttProperties; -import cc.yunxi.utils.CustomerMqttClient; -import lombok.extern.slf4j.Slf4j; -import org.eclipse.paho.mqttv5.common.MqttException; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import javax.annotation.Resource; - - -@Slf4j -//@Configuration -//@EnableConfigurationProperties(MqttProperties.class) -public class MqttConfig { - -// @Resource - private MqttProperties properties; - -// @Bean - public CustomerMqttClient customerMqttClient() throws MqttException { - CustomerMqttClient client = new CustomerMqttClient(); -// client.setMqttProperties(properties); - client.connect(); - log.info("===========> MQTT连接成功 <==========="); - return client; - } -} - diff --git a/nxhs-service/src/main/java/cc/yunxi/utils/MqttTool.java b/nxhs-service/src/main/java/cc/yunxi/utils/MqttTool.java deleted file mode 100644 index 64163b8..0000000 --- a/nxhs-service/src/main/java/cc/yunxi/utils/MqttTool.java +++ /dev/null @@ -1,54 +0,0 @@ -package cc.yunxi.utils; - -import lombok.extern.slf4j.Slf4j; -import org.eclipse.paho.mqttv5.client.MqttClient; -import org.eclipse.paho.mqttv5.common.MqttException; -import org.eclipse.paho.mqttv5.common.MqttMessage; - -//@Component -@Slf4j -public class MqttTool { - - // @Resource - private MqttClient client; - - public boolean publish(String topic, MqttMessage message) { - try { - client.publish(topic, message); - log.warn("发布成功,topic:{},message:{}", topic, message.getPayload()); - return true; - } catch (MqttException e) { - log.error("发布失败,topic:{},message:{}", topic, message.getPayload(), e); - e.printStackTrace(); - return false; - } - } - - public boolean subscribe(String topic, int qos) { - try { - if (client.isConnected() == false) { - log.warn("链接已断开,topic:{},qos:{}", topic, qos); - } - client.subscribe(topic, qos); - log.warn("订阅成功,topic:{},qos:{}", topic, qos); - return true; - } catch (MqttException e) { - log.warn("订阅主题失败,topic:{},qos:{}", topic, qos); - e.printStackTrace(); - return false; - } - } - - public boolean isConnected() { - return client.isConnected(); - } - - public void setWill() throws MqttException { - // 设置遗嘱 - String willTopic = "willTopic"; - String willMessage = "willMessage"; - int willQos = 2; - boolean willRetain = false; -// (willTopic, willMessage.getBytes(), willQos, willRetain); - } -}