1、1 简介
死信队列,英文缩写:DLX 。Dead Letter Exchange(死信交换机),当消息成为Dead message后,可以被重新发送到另一个交换机,这个交换机就是DLX。
1、2 消息成为死信的三种情况:
队列消息长度到达限制;
消费者拒接消费消息,并且不重回队列;
原队列存在消息过期设置,消息到达超时时间未被消费;
2、1 代码实现
public static final String TEST_DLX_EXCHANGE_NAME = "test_dlx_exchange";
public static final String TEST_DLX_QUEUE_NAME = "test_dlx_queue";
public static final String DLX_EXCHANGE_NAME = "dlx_exchange";
public static final String DLX_QUEUE_NAME = "dlx_queue";
@Bean("SpringBootDLXExchange")
public Exchange DLXExchange(){
return ExchangeBuilder.topicExchange(DLX_EXCHANGE_NAME).durable(true).build();
}
@Bean("SpringBootDLXQueue")
public Queue DLXQueue() {
return QueueBuilder.durable(DLX_QUEUE_NAME).build(