KKSU
2024-09-30 36be00e0f3cbe0d559c646fd2977e6e3a74aa6f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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) {
 
    }
}