-
Notifications
You must be signed in to change notification settings - Fork 6k
/
Copy pathRabbitConfig.java
40 lines (34 loc) · 1.28 KB
/
RabbitConfig.java
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
package cn.iocoder.springboot.lab39.skywalkingdemo.config;
import cn.iocoder.springboot.lab39.skywalkingdemo.message.DemoMessage;
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.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RabbitConfig {
// 创建 Queue
@Bean
public Queue demoQueue() {
return new Queue(DemoMessage.QUEUE, // Queue 名字
true, // durable: 是否持久化
false, // exclusive: 是否排它
false); // autoDelete: 是否自动删除
}
// 创建 Direct Exchange
@Bean
public DirectExchange demoExchange() {
return new DirectExchange(DemoMessage.EXCHANGE,
true, // durable: 是否持久化
false); // exclusive: 是否排它
}
// 创建 Binding
// Exchange:DemoMessage.EXCHANGE
// Routing key:DemoMessage.ROUTING_KEY
// Queue:DemoMessage.QUEUE
@Bean
public Binding demoBinding() {
return BindingBuilder.bind(demoQueue()).to(demoExchange()).with(DemoMessage.ROUTING_KEY);
}
}