package com.yunfeiyun.agmp.common.framework.mq;

import com.alibaba.fastjson2.JSON;
import com.yunfeiyun.agmp.common.constant.AmqpConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MqService {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    AmqpTemplate amqpTemplate;


    public void sendMsg(MqMsg mqMsg)  throws Exception{
        try {
            Message message = MessageBuilder.withBody(JSON.toJSONString(mqMsg).getBytes()).build();
            this.amqpTemplate.convertAndSend(AmqpConstant.FanoutExchangeName, "",message);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
