package com.xcong.excoin.rabbit.producer; import com.alibaba.fastjson.JSONObject; import com.xcong.excoin.configurations.RabbitMqConfig; import com.xcong.excoin.netty.bean.ChatRequest; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.connection.CorrelationData; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.UUID; @Slf4j @Component public class ChatProducer implements RabbitTemplate.ConfirmCallback { @Autowired private RabbitTemplate rabbitTemplate; public void sendMsgHistory(ChatRequest chatRequest) { CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString()); log.info("消息持久化消息: {}, {}", chatRequest, correlationData.getId()); String str = JSONObject.toJSONString(chatRequest); rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_ONE, RabbitMqConfig.ROUTING_KEY_MSG_HISTORY, str, correlationData); } @Override public void confirm(CorrelationData correlationData, boolean b, String s) { } }