package com.zcxk.rmcp.web.util;

import com.alibaba.fastjson.JSON;
import com.zcxk.core.common.pojo.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MessageSendUtil {
    @Autowired
    private AmqpTemplate rabbitTemplate;
    @Value("${receive.exchange.name}")
    private  String receiveExchangeName;
    @Value("${dispath.routing.key}")
    private  String dispathRoutingKey;
    public void send(Message message){
        log.debug("消息发送 exchange={}  routingkey={} 用户id={}",receiveExchangeName,dispathRoutingKey,message.getUserId());
        rabbitTemplate.convertAndSend(receiveExchangeName,dispathRoutingKey, JSON.toJSONString(message));
    }
}
