消息被拒绝 (basic.reject or basic.nack) 且带 requeue=false 参数
消息的TTL-存活时间已经过期
队列长度限制被超越(队列满)
Dead letter exchanges (DLXs) are normal exchanges.
For any given queue, a DLX can be defined by clients using the queue's arguments, or in the server using policies.
Dead Letter Pattern
“死信”模式指的是,当消费者不能处理接收到的消息时,将这个消息重新发布到另外一个队列中,等待重试或者人工干预。
这个过程中的exchange和queue就是所谓的"Dead Letter Exchange 和 Queue"。
关键是如何区分“消费失败”和“处理失败”?消费失败需要送到死信队列,而处理失败不需要。大部分情况都属于“处理失败”。
常见问题:
1、consumer启动时报告异常 com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'x-dead-letter-exchange' for queue 'queue_emailsend_result' in vhost 'host_test': received the value 'dlx' of type 'longstr' but current is none, class-id=50, method-id=10)
原因:queue已经存在,但是启动 consumer 时试图设定一个 x-dead-letter-exchange 参数,这和服务器上的定义不一样,server 不允许所以报错。如果删除 queue 重新 declare 则不会有问题。或者通过 policy 来设置这个参数也可以不用删除队列。
参考blog