For items in an Azure queue that my application cannot process, I want them in a dead letter queue.
Ignoring the differences between a DLQ and a PMQ, we only want to be able to deal with two queues. Right now, when dequeue count exceeds my retry limit the SDK moves my messages from emp-details to a queue called emp-details-poison (which if not present, it creates). I want it to move the failed messages to emp-details-dead-letter. Is this possible at all?
I cannot find this in documentation. AI suggests using
"extensions": {
"queues": {
"maxDequeueCount": 3, // Number of times to attempt processing before sending to poison/dead letter queue
/*OPTION1*/ "poisonQueueNameSuffix": "-dead-letter" // Name of the poison queue suffix
/*OPTION2*/ "poisonQueueName": "myqueue-poison" // Name of the poison queue
}
}
Both poisonQueueNameSuffix and poisonQueueName are non existent in the host.json spec. The documentation suggests manually dequeuing messages to a custom queue - but it seems wasteful to do
if (message.DequeueCount >= _maxRetryCount)
{
_logger.LogWarning($"Message {message.MessageId} has reached max retry count ({_maxRetryCount}). Moving to custom poison queue.");
await MoveToCustomDeadLetterQueueAsync(message);
return; // Complete the function successfully to remove from original queue
}
An if check for every single message is going to chalk up significant delays.
How do I use a custom queue for "-poison" messages?
Edit: What I ended up doing:
Not being able to use custom DLQ or PMQ names seems very archaic. Regardless, below is roughly what I ended up doing for a QueueTrigger function. Used Polly to setup a retry count - maxRetryCount and move a message to the required queue when the count exceeds.
var policyResult = await _retryPolicy
.ExecuteAndCaptureAsync(async (context) =>
{
employeeDetailsUpdated = await _empService.UpdateEmpDetails(oid);
},
new Context {
{
"MessageId", message.MessageId
}
});//new Context and policyResult in Polly are important parts of managing contextual information during retries.
//policyResult.Outcome will be OutcomeType.Failure after the policy has exhausted all of its retry attempts (after reaching _maxRetryCount)
if (policyResult.Outcome == OutcomeType.Failure)
{
//if 3 attempts to dequeue have failed, then move the message to dead letter queue. By default, azure moves failed messages to {queuename}-poison queue
_logger.LogWarning("Message {MessageId} has reached max retry count. Moving to custom dead letter queue.", message.MessageId);
await EmpDetailsUpdateDeadLetter(oid);// The original message will still be completed/removed from the queue
}

