前言
死信,在官网中对应的单词为“Dead Letter”,它是 RabbitMQ 的一种消息机制。
生产者将消息投递到 broker 或者直接到 queue 里了,consumer 从 queue 取出消息进行消费,如果它一直无法消费某条数据,那么可以把这条消息放入死信队列里面。等待 条件满足了再从死信队列中取出来再次消费,从而避免消息丢失。
死信消息来源:
消息 TTL 过期
队列满了,无法再次添加数据
消息被拒绝(reject 或 nack),并且 requeue =false
其他的在前面那篇有介绍,这里就直接上代码了
一.生产者建立 DeadConfig 类
package com.lj.provider.mq;
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;
import java.util.HashMap;
import java.util.Map;
@Configuration
@SuppressWarnings("all")
public class DeadConfig {
//创建正常队列
@Bean
public