package cn.com.ty.lift.push.app;

import cn.com.ty.lift.common.constants.WebSocketConstants;
import cn.com.ty.lift.common.model.TimeMessage;
import cn.com.ty.lift.push.message.service.TimeMessageService;
import cn.com.ty.lift.push.websocket.handler.TimeyMessageHandler;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 消息推送消费者，监听队列，从队列中取出message执行推送, queue >>> device platform
 *
 * @author wcz
 * @since 2020/4/26
 */
@Slf4j
@Component
@AllArgsConstructor
public class PushConsumer {

    private TimeMessageService TimeMessageService;

    @JmsListener(destination = WebSocketConstants.PUSH_MESSAGE_TO_PC)
    public void listenPCAllQueue(List<TimeMessage> timeMessageList) {
        log.info("listen {} receive message: {}", WebSocketConstants.PUSH_MESSAGE_TO_PC, timeMessageList);
        TimeyMessageHandler timeMessageHandler = new TimeyMessageHandler(TimeMessageService);
        timeMessageHandler.saveAndPushMessageToUsers(timeMessageList);
    }
}