//package com.yzt.airconditionersystem.bean.mqtt;
//
//import com.yzt.airconditionersystem.service.MqttService;
//import org.eclipse.paho.client.mqttv3.*;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
///**
// * 订阅者
// * @author TzZach
// * @since 2022-05-10 22:47
// */
//@Component
//public class MqttCallback implements MqttCallbackExtended {
//
//    @Value("${spring.mqtt.consumerTopic}")
//    private String[] consumerTopics;
//
//    @Autowired
//    private MqttService mqttService;
//
//    private MqttClient mqttClient;
//
//    @Override
//    public void connectComplete(boolean b, String s) {
//        try {
//            mqttClient.subscribe(consumerTopics);
//        } catch (MqttException e) {
//            e.printStackTrace();
//        }
//    }
//
//    @Override
//    public void connectionLost(Throwable throwable) {
//        System.out.println("连接断开");
//    }
//
//    @Override
//    public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
//        mqttService.sendToMqtt(topic, mqttMessage);
//    }
//
//    @Override
//    public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
//        System.out.println("deliveryComplete------" + iMqttDeliveryToken.isComplete());
//    }
//
//    public void setMqttClient(MqttClient mqttClient) {
//        this.mqttClient = mqttClient;
//    }
//}
