KKSU
2024-04-16 1d5f689f34d827ac4be67fd84212a5cb7fc80d57
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package cc.mrbird.febs.rabbit.producer;
 
import cc.mrbird.febs.rabbit.QueueEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
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;
 
/**
 * @author wzy
 * @date 2022-05-31
 **/
@Slf4j
@Component
public class ChainProducer implements RabbitTemplate.ConfirmCallback {
 
    /**
     * 配置中配置的RabbitTemplate的是prototype类型,不能直接注入
     */
    private RabbitTemplate rabbitTemplate;
 
    @Autowired
    public ChainProducer(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
        rabbitTemplate.setConfirmCallback(this);
    }
 
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
 
    }
 
    public void sendOnlineTransfer(String batchNo) {
        log.info("发送链上转账消息:{}", batchNo);
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(QueueEnum.ONLINE_TRANSFER.getExchange(), QueueEnum.ONLINE_TRANSFER.getRoute(), batchNo, correlationData);
    }
 
    public void sendDitribProfit(Long id) {
        log.info("发送滑点分配消息:{}", id);
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(QueueEnum.GFA_ZY_HUA_DIAN.getExchange(), QueueEnum.GFA_ZY_HUA_DIAN.getRoute(), id, correlationData);
    }
 
    public void sendUserBuyReward(Long id) {
        log.info("发送用户购买奖励消息:{}", id);
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(QueueEnum.USER_BUY_REWARD.getExchange(), QueueEnum.USER_BUY_REWARD.getRoute(), id, correlationData);
    }
 
 
    public void sendZhiYaDelayMsg(Long id, Long times) {
        log.info("发送延时质押消息:{}, {}", id, times);
        rabbitTemplate.convertAndSend(QueueEnum.GFA_ZY_TIME_TTL.getExchange(),
                QueueEnum.GFA_ZY_TIME_TTL.getRoute(),
                id, new MessagePostProcessor() {
                    @Override
                    public Message postProcessMessage(Message message) throws AmqpException {
                        message.getMessageProperties().setExpiration(String.valueOf(times));
                        return message;
                    }
                });
    }
 
 
    public void sendZhiYaDelayFlowMsg(Long id, Long times) {
        log.info("发送延时质押流水消息:{}, {}", id, times);
        rabbitTemplate.convertAndSend(QueueEnum.GFA_ZY_TIME_TTL_FLOW.getExchange(),
                QueueEnum.GFA_ZY_TIME_TTL_FLOW.getRoute(),
                id, new MessagePostProcessor() {
                    @Override
                    public Message postProcessMessage(Message message) throws AmqpException {
                        message.getMessageProperties().setExpiration(String.valueOf(times));
                        return message;
                    }
                });
    }
}