A broker retries messages that fail because some failures are temporary. Once a message exceeds the retry budget, continuing to retry it can block useful work and overload an unhealthy dependency. The broker moves that message to a dead-letter queue (DLQ) for inspection or later replay.
Design a DeadLetterRouter class:
DeadLetterRouter() creates a stateless router.String[] classify(int[] failures, int maxRetries) returns the final disposition of every message.
failures[i] is the number of times message i failed before it either succeeded or exhausted the configured policy:
- Return
"delivered" when failures[i] <= maxRetries. - Return
"dlq" when failures[i] > maxRetries.
Preserve the input order. Each call is independent, and the input array must not be mutated.
Example 1:
Input:
Output:
Explanation: The messages with 0, 2, and 1 failures stay within the two-retry budget. The messages with 3 and 4 failures exceed it and are routed to the DLQ.
Example 2:
Input:
Output:
Explanation: With no retries configured, a message that has zero failures is still delivered because its initial processing attempt succeeds.
Constraints
0 <= failures.length <= 10^50 <= failures[i] <= 10^90 <= maxRetries <= 10^9- Return exactly one disposition for each message.
- At most
100 calls are made to classify.