When a message fails to be consumed for the first time, the MSMQ automatically retries the message. After the maximum number of retries is reached, if the consumption still fails, it indicates that the consumer cannot consume the message correctly under normal circumstances. At this point, the MSMQ does not immediately discard the message, but sends it to the special queue corresponding to the consumer. In MSMQ, messages that cannot be consumed normally are called dead-letter messages (Dead-Letter Message). Dead-letter queues (Dead-Letter Queue) are used to store and process these dead-letter messages that cannot be consumed normally.
This topic describes how to query and resend dead-letter messages that enter a dead-letter queue. This allows you to manage dead-letter messages as needed to avoid missing messages.
Feature description
Dead-letter queue
A dead-letter queue corresponds to a group ID instead of a single consumer instance.
If no dead-letter messages are generated for a group ID, the MSMQ does not create a dead-letter queue for the group ID.
A dead-letter queue contains all dead-letter messages generated by a group ID, regardless of the topic to which the messages belong.
Dead-letter messages
It will no longer be consumed normally by consumers.
The validity period of a message is the same as that of a normal message. The message is valid for three days. After three days, the message is automatically deleted. Therefore, please handle the dead-letter message within 3 days after it is generated.
Query dead-letter messages
MSMQ provides the following methods to query dead-letter messages:
Query by group ID: All messages that meet the specified conditions are obtained in batches based on the group ID and time range. The query volume is large and difficult to match.
Query by message ID: You can accurately locate any message based on the group ID and message ID.
Query by group ID
You can query all dead-letter messages generated by a group ID within a specified period of time based on the group ID and the time range in which the dead-letter messages are generated.
The time when a dead-letter message is generated refers to the time when a message is sent to the dead-letter queue after the maximum number of delivery retries is reached.
Procedure
Log on to the SOFAStack console.
In the left-side navigation pane, choose Middleware > MSMQ > Dead-Letter Queue.
Click Query by Group ID. In the Group ID field, enter the group ID that you want to search for in the keyword search box and select it or select the group ID from the drop-down list.
Click the time selection box and select the start and end dates and a specific time point of the time range that you want to query.
Click Search. All dead-letter messages that meet the preceding conditions are displayed.
Find a dead-letter message and click Message Details in the Actions column to view the message details, including the message body size and basic attributes.
Find the target dead-letter message and click Message Trace in the Actions column. On the Message Trace page, you can view the message trace. For more information, see Query message traces.
Query by message ID
Querying messages by message ID is an exact query. You can query a message based on the group ID and message ID.
Procedure
Log on to the SOFAStack console.
In the left-side navigation pane, choose Middleware > MSMQ > Dead-Letter Queue.
Click Query by Message ID. In the Group ID field, enter the keyword group ID that you want to search for, and select it or select the group ID from the drop-down list.
In the Message ID field, enter the ID of the message that you want to find.
Click Search. All dead-letter messages that meet the preceding conditions are displayed.
Find the target dead-letter message and click Message Details in the Actions column to view the message details, including the basic properties and download link of the message body.
Find the target dead-letter message and click Message Trace in the Actions column. On the Message Trace page, you can view the message trace. For more information, see Query message traces.
Consumption verification
You can also use the consumption verification feature to verify whether a specified consumer application can receive messages.
The consumption verification function is only used to verify whether the consumption logic of the client is normal and does not affect the normal message receiving process. Therefore, the consumption status and other information of the message will not change after the consumption verification.
Procedure:
On the details page of the dead-letter message, find the group ID and click Consume Verification in the Actions column.
In the Consumption Verification window, select the target consumer application IP.
Click OK. The message is resent to the specified IP address.
Resend dead-letter messages
If a message enters a dead-letter queue, the consumer cannot consume the message. Therefore, you must handle the message. After you troubleshoot the suspicious factors and resolve the issue, you can resend the message in the MSMQ console to have the consumer consume it again.
After a dead-letter message is resent, it is not immediately deleted from the dead-letter queue.
Resend a dead-letter message in the MSMQ console. Find the dead-letter message that you want to resend and click Resend in the Actions column.
Batch Resend After you find dead-letter messages by group ID in the MSMQ console, select the target dead-letter messages and click Batch Resend in the lower part of the page to resend all the selected dead-letter messages.