package com.sky.ioc;

import com.sky.ioc.message.MQTTSubsribe;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

import javax.annotation.PostConstruct;

@SpringBootApplication
public class SkyIocApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(SkyIocApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(SkyIocApplication.class, args);
    }

    @Autowired
    private MQTTSubsribe mqttSubsribe;

    @Value("${spring.profiles.active}")
    private String active;
    /**
     * 接受订阅的接口和消息,mqtt消费端
     */
    @PostConstruct
    public void consumeMqttClient() throws MqttException {
        if(active.equals("publish")){
            mqttSubsribe.start("notice/device/status/safety/camera,notice/device/status/energy/device");
       }

    }

}
