package com.skr.mdm.rabbitmq;

import com.skr.mdm.bean.dto.AlarmPushDTO;
import com.skr.mdm.bean.dto.UserLoginCallbackDTO;
import com.skr.mdm.bean.so.RabbitMqSO;
import com.skr.mdm.constant.RabbitmqExchangeConstants;
import com.skr.mdm.constant.RabbitmqRoutingKeyConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author nfq
 * @date 2020/6/16 14:51
 */

@Component
@Slf4j
public class RabbitMQProvider {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 推送数据到websocket
     * @param rabbitMqSO
     */
    public void pushDataWithWebsocket(RabbitMqSO rabbitMqSO) {
        rabbitTemplate.convertAndSend(RabbitmqExchangeConstants.TOPIC_EXCHANGE, RabbitmqRoutingKeyConstants.WEBSOCKET_ROUTING_KEY, rabbitMqSO);
    }

    /**
     * 手机端注册发布
     * @param userLoginCallbackDTO
     */
    public void publishRegisterEventWithDelayed(UserLoginCallbackDTO userLoginCallbackDTO) {
        // 延时10秒后发送，待客户端websocket连接后推送
        log.info("延时队列10秒后发送消息");
        rabbitTemplate.convertAndSend(RabbitmqExchangeConstants.DELAYED_EXCHANGE,
                RabbitmqRoutingKeyConstants.CLIENT_REGISTER_ROUTING_KEY, userLoginCallbackDTO, message -> {
            message.getMessageProperties().setDelay(10000);
           return message;
        });
    }


}