package cn.van.business.mq;

import com.alibaba.fastjson2.JSONObject;
import lombok.SneakyThrows;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Leo
 * @version 1.0
 * @create 2024/12/1 上午2:06
 * @description：
 */
@Service
public class MessageProducerService {

    private static final Logger logger = LoggerFactory.getLogger(MessageProducerService.class);

    private static final String topic = "wx-message";

    private final RocketMQTemplate rocketMQTemplate;

    public MessageProducerService(RocketMQTemplate rocketMQTemplate) {
        this.rocketMQTemplate = rocketMQTemplate;
    }

    @SneakyThrows
    public void sendMessage(JSONObject jsonObject) {
        Message message = new Message(topic, jsonObject.toJSONString().getBytes());
        message.setTags("wx");
        this.rocketMQTemplate.convertAndSend(topic, message);

    }
}
