Helius
2022-05-31 f7fc7c82d2d683a3e90e88ddbf8831bfa3800e11
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
package cc.mrbird.febs.rabbit;
 
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
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());
    }
}