I want to implement DLX in rabbit MQ which sets the retry count for the failed messages. If the retry count is greater then 5 then the message will automatically be discarded.
Below is the snippet for the DLX.
string WORK_EXCHANGE = "DeadExchange"; // dead letter exchange
string RETRY_QUEUE = "RetryQueue";
int RETRY_DELAY = 10000;
var queueArgs = new Dictionary<string, object> {
{ "x-dead-letter-exchange", WORK_EXCHANGE },
{ "x-message-ttl", RETRY_DELAY }
};
var properties = channel.CreateBasicProperties();
properties.Persistent = true;
channel.ExchangeDeclare(exchange: WORK_EXCHANGE,
type: ExchangeType.Direct);
channel.QueueBind(queue: queueName, exchange: WORK_EXCHANGE, routingKey: routingKey, arguments: null);
channel.ExchangeDeclare(exchange: RETRY_EXCHANGE,
type: ExchangeType.Direct);
channel.QueueDeclare(queue: RETRY_QUEUE, durable: true, exclusive: false, autoDelete: false, arguments: queueArgs);
channel.QueueBind(queue: RETRY_QUEUE, exchange: RETRY_EXCHANGE, routingKey: routingKey, arguments: null);
channel.BasicPublish(exchange: RETRY_EXCHANGE, routingKey: routingKey, mandatory: true, basicProperties: properties, body: message);
I want to read x-Death property as shown in below queue message.
So far I have reached
(BasicDeliveryEventArgs)ea.BasicProperties.Headers["x-death"]