The MQ console provides several message query methods to assist you in troubleshooting.
MQ provides you with three ways to query messages: by message ID, by message key, and by topic.
Their characteristics are compared as follows:
|By message ID||Topic + message ID||Exact query||By specifying the topic and message ID, you can locate any message precisely and obtain the properties of the message.|
|By message key||Topic + message key||Fuzzy query||By specifying the topic and message key, you can query the latest 64 messages with the specified key. It is suggested that the message producer set a key as unique as possible for each message, to ensure that the number of messages with the same key does not exceed 64. Otherwise, some messages could be missed in the query.|
|By topic||Topic + time range||Range query||By specifying the topic and time range, you can obtain all the messages that meet the conditions in batches. The query volume is large and only fuzzy matching can be implemented.|
Recommended query process:
Exact matching can be implemented if you query by message ID. You can obtain an exact message by specifying its topic and message ID. Therefore, we recommend that you print the message ID to the log after the message is sent upon producer calling, to facilitate exact query and troubleshooting.
Take Java SDK for example. The message ID can be obtained as follows:
SendResult sendResult = producer.send(msg);
String msgId = sendResult.getMessageId();
After querying a message, you can view its basic properties, body download link, and consumption status on the Message Details page.
The delivery status is calculated by MQ based on the consumption progress of each group ID. The following table describes the delivery statuses.
Note: The delivery status is only an estimation based on the consumption progress. To get more detailed consumption information, use the message tracing function. The message tracing function displays the complete link of the message. For more information, see Query message traces.
|Delivery status||Possible reasons|
|Subscribed to, and consumed at least once||The group ID has consumed this message normally.|
|Subscribed to, but filtered out by a filter expression, check the tag||The group ID has not subscribed to the tag of the message, and therefore, the message has been filtered out. To check the subscription of a group ID, go to the Consumers page in the console and click Consumer Status in the Actions column.|
|Subscribed to, but not consumed||The group ID has subscribed to the message, but has not yet consumed it. This can be caused by slow consumption or an exception-caused consumption block.|
|Messages are subscribed but the consumer is offline. Please use the message tracing function for accurate message queries.||The group ID has subscribed to the message, but is offline. Check the reason why the consumer is offline.|
|Unknown exception||An unlisted exception occurred. Submit a ticket to seek help from Customer Services.|
MQ provides a consumption verification function that allows pushing a specified message to a designated online client to detect whether the logic and result of message consumption by the client are as expected.
Note: The consumption verification function is only for verifying whether the consumption logic on the client is normal and does not affect a normal message receiving process, so consumption status and other information of the message does not change after clicking for consumption verification.
The mechanism of query by message key is that MQ creates an index for the messages according to message keys that you provide, so that when you query by message key, the messages matching the index can be found and returned.
- The condition for query by message key is the message key property you set.
- Only the most recent 64 messages that meet the condition can be returned in a query by message key. Therefore, we recommend that you set a key as unique as possible and make a service distinction.
To set a message key:
Message msg = new Message("Topic","*","Hello MQ".getBytes());
* Set the key to be retrieved for each message. The key value represents the key attribute of the message. Set it as unique as possible.
* If you have trouble in receiving a message, you can query the message in the MQ console. Messages can be sent and received as usual even if this attribute is not set.
If you cannot retrieve any data using the preceding two methods, query messages by topic. You can specify the topic and message sending time range to retrieve messages in batches and then locate the data that you are concerned about.
- Query by topic is a range query for obtaining all messages meeting the time condition under the topic, so the number of retrieved messages is large and we recommend that you shorten the query interval to the greatest extent.
- Query by topic involves a large amount of data, which is usually displayed on multiple pages.