xiaoyong931011
2023-10-30 c1ca2981080dbd1d487758fb5f16719aa6d68489
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
85
package cc.mrbird.febs.rabbit.producter;
 
import cc.mrbird.febs.rabbit.constants.ExchangeConstants;
import cc.mrbird.febs.rabbit.constants.RouteKeyConstants;
import cc.mrbird.febs.rabbit.enumerates.RabbitQueueEnum;
import cn.hutool.core.util.IdUtil;
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 javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.UUID;
 
/**
 * @author wzy
 * @date 2021-09-25
 **/
@Slf4j
@Component
public class AgentProducer implements RabbitTemplate.ConfirmCallback {
 
    /**
     * 配置中配置的RabbitTemplate的是prototype类型,不能直接注入
     */
    private RabbitTemplate rabbitTemplate;
 
    /**
     * 在构造方法上注入RabbitTemplate
     *
     * @param
     */
    @Autowired
    public AgentProducer(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
        rabbitTemplate.setConfirmCallback(this);
    }
 
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
 
    }
 
    /**
     * 添加会员
     */
    public void sendAddRobotMsg(String inviteId) {
        log.info("添加会员:{}", inviteId);
        CorrelationData correlationData = new CorrelationData(IdUtil.simpleUUID());
        rabbitTemplate.convertAndSend(RabbitQueueEnum.IM_REDBAG_GET_ADD_ROBOT.getExchange(),
                RabbitQueueEnum.IM_REDBAG_GET_ADD_ROBOT.getRoute(),
                inviteId,
                correlationData);
    }
 
    /**
     * 自动发送
     */
    public void sendAutoSendMsg(Long groupId) {
//        log.info("自动发送:{}", groupId);
        CorrelationData correlationData = new CorrelationData(IdUtil.simpleUUID());
        rabbitTemplate.convertAndSend(RabbitQueueEnum.IM_REDBAG_AUTO_SEND.getExchange(),
                RabbitQueueEnum.IM_REDBAG_AUTO_SEND.getRoute(),
                groupId,
                correlationData);
    }
 
    /**
     * 自动返还
     */
    public void sendOverdueSendMsg(Long redbagId) {
        log.info("自动返还:{}", redbagId);
        CorrelationData correlationData = new CorrelationData(IdUtil.simpleUUID());
        rabbitTemplate.convertAndSend(RabbitQueueEnum.IM_REDBAG_OVERDUE.getExchange(),
                RabbitQueueEnum.IM_REDBAG_OVERDUE.getRoute(),
                redbagId,
                correlationData);
    }
 
}