package iot.lidee.iot.data.listen;

import iot.lidee.common.constant.LideeConstant;
import iot.lidee.common.core.mq.MQSendMessageBo;
import iot.lidee.iot.data.consumer.FunctionInvokeConsumer;
import iot.lidee.mq.queue.FunctionInvokeQueue;
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 FunctionInvokeListen {

    @Autowired
    private FunctionInvokeConsumer functionInvokeConsumer;

    @Async(LideeConstant.TASK.MESSAGE_CONSUME_TASK)
    public void listen() {
        while (true) {
            try {
                MQSendMessageBo sendBo = FunctionInvokeQueue.take();
                functionInvokeConsumer.handler(sendBo);
            } catch (Exception e) {
                log.error("=>下发服务消费异常", e);
            }
        }
    }
}
