forked from chengxy-nds/Springboot-Notebook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeadLetterConfig.java
More file actions
71 lines (60 loc) · 1.95 KB
/
DeadLetterConfig.java
File metadata and controls
71 lines (60 loc) · 1.95 KB
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
package com.chengxy.delayqueue.deadLetterQueue;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @Author: xiaofu
* @Description:
*/
@Configuration
public class DeadLetterConfig {
/**
* 正常消费队列
*/
@Bean
public Queue messageQueue() {
return new Queue(RabbitConstant.IOT_VIRTUAL_DEVICE_CLOSE_QUEUE);
}
/**
* 正常消费交换机
*/
@Bean
public DirectExchange messageDirectExchange() {
return new DirectExchange(RabbitConstant.IOT_VIRTUAL_DEVICE_CLOSE_EXCHANGE);
}
/**
* 正常消费队列与交换机绑定
*/
@Bean
public Binding bingdingMessageExchangeAndQueue() {
return BindingBuilder.bind(messageQueue()).to(messageDirectExchange()).with(RabbitConstant.IOT_VIRTUAL_DEVICE_CLOSE_QUEUE);
}
/**
* 延时队列
*/
@Bean
public Queue delayMessageQueue() {
return QueueBuilder
.durable(RabbitConstant.IOT_VIRTUAL_DEVICE_DELAY_QUEUE)
// 配置到期后转发的交换
.withArgument("x-dead-letter-exchange", RabbitConstant.IOT_VIRTUAL_DEVICE_CLOSE_EXCHANGE)
// 配置到期后转发的路由键
.withArgument("x-dead-letter-routing-key", RabbitConstant.IOT_VIRTUAL_DEVICE_CLOSE_QUEUE)
.build();
}
/**
* 延时交换机
*/
@Bean
public DirectExchange delayMessageDirectExchange() {
return new DirectExchange(RabbitConstant.IOT_VIRTUAL_DEVICE_DELAY_EXCHANGE);
}
/**
* 延时队列与交换机绑定
*/
@Bean
public Binding bingdingDeadLetterExchangeAndQueue() {
return BindingBuilder.bind(delayMessageQueue()).to(delayMessageDirectExchange()).with(RabbitConstant.IOT_VIRTUAL_DEVICE_DELAY_QUEUE);
}
}