RabbitMQ 实现延迟队列的方式主要有两种:死信交换机、延迟队列插件 死信交换机的实现步骤是:
① 声明死信交换机并编写监听方法
② 声明延迟队列和对应的交换机,在声明队列时配置ttl、dead-letter-exchange、dead-letter-routing-key属性
③ 发送消息时,设置超时时间(实际上延迟队列的ttl和消息的超时时间至少有一个设置了就行) 延迟队列插件的实现步骤是:
① 声明一个交换机,设置 delayed 属性为true
② 发送消息时,添加 x-delay 头,值为超时时间