package iot.lidee.iot.data.listen;

import iot.lidee.common.constant.LideeConstant;
import iot.lidee.common.core.mq.DeviceStatusBo;
import iot.lidee.iot.data.consumer.DeviceStatusConsumer;
import iot.lidee.mq.queue.DeviceStatusQueue;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 设备状态监听
 * @author bill
 */
@Slf4j
@Component
public class DeviceStatusListen {

    @Autowired
    private DeviceStatusConsumer deviceStatusConsumer;

    @Async(LideeConstant.TASK.MESSAGE_CONSUME_TASK)
    public void listen() {
        try {
            while (true) {
                DeviceStatusBo status = DeviceStatusQueue.take();
                deviceStatusConsumer.consume(status);
            }
        } catch (Exception e) {
            log.error("设备状态监听错误", e);
        }
    }

}
