DLX,Dead-Letter-Exchange(死信邮箱)
利用DLX,当消息在一个队列中变成死信后,它能被重新publish到另一个Exchange,这个Exchange就是DLX。消息变成死信一向有以下几种情况:
消息被拒绝(basic.reject or basic.nack)并且requeue=false;
配置两个队列 一个workqueue ,一个re_workqueue 配置对应的参数
一. workqueue 1.x-dead-letter-exchange : workexchange x-dead-letter-routing-key: re_routingkey 2. bind:workexchange routingkey
二. re_workqueue 1.x-dead-letter-exchange : workexchange x-dead-letter-routing-key: routingkey x-message-ttl 2. bind: workexchange re_routingkey
监听:
ev.Received += (o, e) =>
{
var dicparas = e.BasicProperties.Headers;
}
如果是死信邮箱重发的消息 e.BasicProperties.Headers 是一个字典 里面有key "x-death" ,value 种 有count字段,为重试的次数。
http://www.codeweblog.com/%E5%8E%9F%E5%88%9B-rabbitmq-%E4%B9%8B-dead-letter-exchanges-%E7%BF%BB%E8%AF%91/