KKSU
2024-04-19 af18f13ad4056a6a2f134c6fa3ccf6e0d67ad2be
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package cc.mrbird.febs.rabbit;
 
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
 
import javax.annotation.Resource;
 
/**
 * @author wzy
 * @date 2022-05-31
 **/
@Configuration
public class RabbitConfiguration {
 
    @Resource
    private ConnectionFactory connectionFactory;
 
    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public RabbitTemplate rabbitTemplate() {
        return new RabbitTemplate(connectionFactory);
    }
 
    @Bean
    public DirectExchange onlineTransferExchange() {
        return new DirectExchange(QueueEnum.ONLINE_TRANSFER.getExchange());
    }
 
    @Bean
    public Queue onlineTransferQueue() {
        return new Queue(QueueEnum.ONLINE_TRANSFER.getQueue());
    }
 
    @Bean
    public Binding defaultBind() {
        return BindingBuilder.bind(onlineTransferQueue()).to(onlineTransferExchange()).with(QueueEnum.ONLINE_TRANSFER.getRoute());
    }
 
    @Bean
    public DirectExchange distribProfitExchange() {
        return new DirectExchange(QueueEnum.DISTRIB_PROFIT.getExchange());
    }
 
    @Bean
    public Queue distribProfitQueue() {
        return new Queue(QueueEnum.DISTRIB_PROFIT.getQueue());
    }
 
    @Bean
    public Binding distribProfitBind() {
        return BindingBuilder.bind(distribProfitQueue()).to(distribProfitExchange()).with(QueueEnum.DISTRIB_PROFIT.getRoute());
    }
 
    // === 用户购买奖励 start ===
    @Bean
    public DirectExchange userBuyRewardExchange() {
        return new DirectExchange(QueueEnum.USER_BUY_REWARD.getExchange());
    }
 
    @Bean
    public Queue userBuyRewardQueue() {
        return new Queue(QueueEnum.USER_BUY_REWARD.getQueue());
    }
 
    @Bean
    public Binding userBuyRewardBind() {
        return BindingBuilder.bind(userBuyRewardQueue()).to(userBuyRewardExchange()).with(QueueEnum.USER_BUY_REWARD.getRoute());
    }
    // === 用户购买奖励 end ===
 
 
    // === 延时产出  start ===
    @Bean
    public DirectExchange delayExchangeTtl() {
        return new DirectExchange(QueueEnum.GFA_ZY_TIME_TTL.getExchange());
    }
    @Bean
    public Binding orderDelayBindTtl() {
        return BindingBuilder.bind(orderDelayQueueTtl()).to(delayExchangeTtl()).with(QueueEnum.GFA_ZY_TIME_TTL.getRoute());
    }
    @Bean
    public Queue orderDelayQueueTtl() {
        return QueueBuilder.durable(QueueEnum.GFA_ZY_TIME_TTL.getQueue())
                //到期后转发的交换机
                .withArgument("x-dead-letter-exchange", QueueEnum.GFA_ZY_TIME.getExchange())
                //到期后转发的路由键
                .withArgument("x-dead-letter-routing-key", QueueEnum.GFA_ZY_TIME.getRoute())
                .build();
    }
    @Bean
    public DirectExchange orderDelayExchange() {
        return new DirectExchange(QueueEnum.GFA_ZY_TIME.getExchange());
    }
    @Bean
    public Queue orderDelayQueue() {
        return new Queue(QueueEnum.GFA_ZY_TIME.getQueue());
    }
    @Bean
    public Binding orderDelayBind() {
        return BindingBuilder.bind(orderDelayQueue()).to(orderDelayExchange()).with(QueueEnum.GFA_ZY_TIME.getRoute());
    }
    // ===  延时产出  end ===
 
 
    // === 延时产出  start ===
    @Bean
    public DirectExchange delayExchangeTtlFlow() {
        return new DirectExchange(QueueEnum.GFA_ZY_TIME_TTL_FLOW.getExchange());
    }
    @Bean
    public Binding orderDelayBindTtlFlow() {
        return BindingBuilder.bind(orderDelayQueueTtlFlow()).to(delayExchangeTtlFlow()).with(QueueEnum.GFA_ZY_TIME_TTL_FLOW.getRoute());
    }
    @Bean
    public Queue orderDelayQueueTtlFlow() {
        return QueueBuilder.durable(QueueEnum.GFA_ZY_TIME_TTL_FLOW.getQueue())
                //到期后转发的交换机
                .withArgument("x-dead-letter-exchange", QueueEnum.GFA_ZY_TIME_FLOW.getExchange())
                //到期后转发的路由键
                .withArgument("x-dead-letter-routing-key", QueueEnum.GFA_ZY_TIME_FLOW.getRoute())
                .build();
    }
    @Bean
    public DirectExchange orderDelayExchangeFlow() {
        return new DirectExchange(QueueEnum.GFA_ZY_TIME_FLOW.getExchange());
    }
    @Bean
    public Queue orderDelayQueueFlow() {
        return new Queue(QueueEnum.GFA_ZY_TIME_FLOW.getQueue());
    }
    @Bean
    public Binding orderDelayBindFlow() {
        return BindingBuilder.bind(orderDelayQueueFlow()).to(orderDelayExchangeFlow()).with(QueueEnum.GFA_ZY_TIME_FLOW.getRoute());
    }
    // ===  延时产出  end ===
 
 
 
    //滑点 start
    @Bean
    public DirectExchange gfaZhiYaHuaDianExchange() {
        return new DirectExchange(QueueEnum.GFA_ZY_HUA_DIAN.getExchange());
    }
 
    @Bean
    public Queue gfaZhiYaHuaDianQueue() {
        return new Queue(QueueEnum.GFA_ZY_HUA_DIAN.getQueue());
    }
 
    @Bean
    public Binding gfaZhiYaHuaDianBind() {
        return BindingBuilder.bind(gfaZhiYaHuaDianQueue()).to(gfaZhiYaHuaDianExchange()).with(QueueEnum.GFA_ZY_HUA_DIAN.getRoute());
    }
    //滑点 end
}