A company is redesigning its backend infrastructure to use a message-driven architecture. A critical component is an Azure Function that processes messages from an Azure Service Bus queue. The function is occasionally failing due to transient network issues or temporary unavailability of a downstream service. The company needs to ensure that these messages are automatically retried a few times before being moved to a dead-letter queue for manual investigation. Which feature of Azure Functions or Service Bus should be configured?
- AService Bus Message Lock Duration
- BAzure Function App Retry Policy
- CAzure Function App 'Always On' setting
- DService Bus Max Delivery Count
Show answer & explanationAnswer & explanation
Correct answer: D. Service Bus Max Delivery Count
The Azure Service Bus queue's 'Max Delivery Count' property dictates how many times a message can be delivered to a consumer before it's automatically moved to the dead-letter queue. When an Azure Function fails to process a message and abandons it (e.g., due to an unhandled exception), the delivery count is incremented, and the message is made available for re-delivery. This mechanism directly supports automatic retries and dead-lettering.
Why the other options are wrong
- A. Service Bus Message Lock Duration specifies how long a message is locked for a consumer; if the lock expires, the message is available again, but 'Max Delivery Count' governs the total retries before dead-lettering.
- B. While Azure Functions have host-level retry policies, for Service Bus triggers, the native retry mechanism of Service Bus (controlled by Max Delivery Count) is often the primary and most robust way to handle retries before dead-lettering.
- C. 'Always On' keeps the function app running but does not handle message retries for failures.
Service Bus Max Delivery Count
A property of an Azure Service Bus queue or subscription that specifies the maximum number of times a message can be delivered to a consumer before it is automatically moved to the dead-letter queue.
- Default value is 10
- Configurable per queue/subscription
- Protects against infinite retries for poison messages
- Used in conjunction with message locks and abandon operations
Memory trick: Max Delivery Count saves your messages from infinite loops, sending them to the dead-letter queue like a final scoop.