The Dead Letter Queue is same as a normal queue, except that it is created to isolate and analyze messages that another queue (source queue) has not successfully processed. See the [
createqueue () ](create_delete_purge_Queue.md) API for methods for creating dead letter queues, which is no different than creating a normal queue; a dead letter queue cannot invoke the
[
deadmessage (), Deadmessagebatch ](deadMessage.md) APIs. All other operations are the same as for normal queue operations.
To send a message from the source queue that was not successfully processed to the dead letter queue, we added the concept of "redrive policy" for the source queue, with detailed definitions and APIs as follows:
Add a redrive policy for the (source) queue.
Source Queue name
Each queue can only set one redrive policy.
The name of the dead letter queue.
The maximum received number of times received from the source queue. The value range is [1, 100]. Messages received exceeding this number are sent from the source queue to the dead letter queue.
Note: If a redrive policy is set, but the dead letter queue is deleted, all of the source queue's redrive policies for the dead letter queue are invalid. The source queue and dead letter queues should not be topic/priority, and the source queue is not a dead letter queue for other queues, and the dead letter queue cannot have a redrive policy. To view the current queue's redrive policy, use the [
getqueueinfo () ](QueueInfo.md) API.
Source Queue name
Redrive policy.
Remove the redrive policy for the queue.
Source Queue name
Use the [
receivemessage () ](receiveMessage.md) API. The received message attributes additionally contains the following:
Because a dead letter queue may have multiple source queues, to make it easier for users to distinguish different source queue messages, we define a user attribute for messages from the source queue: The name is "DLQ.sourceQueue", the type is "STRING", and the value is the name of the source queue. Users can use this attribute to filter messages from a specific source queue in a dead letter queue.
Note: DLQ.sourceQueue is a user attribute keyword reserved by the system. Users should not use the attribute name.
There are two ways to "send" messages to the dead-letter queue. One way is to use to send messages to normal queues, using the [
sendMessage(), sendMessageBatch](sendMessage.md) APIs. Messages sent this way are received without the above attributes. Another way is to invoke the
[
deadMessage(), deadMessageBatch](deadMessage.md) APIs from the source queue. This process of sending a message can be understood as (source) to another type of the message's ACK, when the user detects that some of the received messages are invalid, the user can actively send these messages to the dead-letter queue for subsequent analysis.
The redrive policy is valid for all tags, but the tag is independent. When some of the messages received in the source queue are sent to the dead letter queue, they will not received again by a receiver using the tag, while a receiver using another tag is still able to receive these messages.