If an error occurs when a consumer consumes messages, you can troubleshoot the error by querying the messages. In the ApsaraMQ for Kafka console, you can query messages by offset or by time.
Background information
You can use one of the following methods to query a message:
- If you know the offset of the message and the ID of the partition where the message is stored, we recommend that you query the message by offset. For more information, see the "Query messages by offset" section of this topic. For information about offsets, see Terms.
- If you do not know the offset of the message but know the time range during which the message is sent, we recommend that you query the message by time. For more information, see the "Query messages by time" section of this topic.
Usage notes
- In the ApsaraMQ for Kafka console, a maximum of 1 KB of content for each queried message is displayed. The excess content of the message is omitted. If you need to view the complete content of a message, download the message.
You can download messages only from Message Queue for Apache Kafka instances of the Professional Edition. You can download up to 10 MB of messages at a time.
- A maximum of 10 messages can be retrieved, and the total size of the queried messages cannot exceed 10 MB.
- If the total size of three queried messages exceeds 10 MB, only two messages are displayed in the console.
- If the total size of 10 queried messages is less than 10 MB, the 10 messages are displayed in the console. However, no more messages can be retrieved in this query. The number of messages actually displayed in the console is subject to the actual consumption data of the consumer.
For more information about instance editions, see Billing.
- The query results are related to the following message cleanup policies of ApsaraMQ for Kafka:
- If the disk usage of an instance is lower than 75%, messages whose retention period expires are deleted at 04:00 every day.
- If the disk usage of an instance is equal to or higher than 75% and lower than 85%, messages whose retention period expires are regularly deleted to keep the disk usage below 75%.
- If the disk usage of an instance is equal to or higher than 85% and lower than 90%, messages stored on the ApsaraMQ for Kafka broker are deleted from the earliest stored message, regardless of whether their retention period expires.
- If the disk usage of an instance is equal to or higher than 90%, no more messages can be sent to the instance. This ensures service stability.
Important When messages are deleted, at least one storage file is retained by ApsaraMQ for Kafka. As a result, when you query messages, the query results may contain messages whose retention period expired.
Query messages by offset
- Log on to the ApsaraMQ for Kafka console.
- In the Resource Distribution section of the Overview page, select the region where your instance is deployed.
- On the Instances page, click the name of the instance that you want to manage.
- In the left-side navigation pane, click Message Query.
- On the Message Query page, select Search by offset from the Search Method drop-down list.
- Select the topic to which the queried message belongs from the Topic drop-down list and the partition to which the queried message belongs from the Partition drop-down list, enter the offset in the Offset field, and then click Search.
Messages whose offsets are equal to or greater than the specified offset are displayed. For example, if you specify 5 as the value of both the Partition parameter and Offset parameter, the system queries messages whose offsets are equal to or greater than 5 from Partition 5.
Table 1. Parameters in the message query results Parameter Description Partition The partition from which the message is obtained. Offset The message offset. Key The message key. The key is converted to a string. Value The message value, which is also known as message content. The message value is converted to a string. Created At The point in time when the message was produced. The value is the timestamp that the producer recorded when the producer sent the message or the timestamp that you specified for ProducerRecord
.Note- If a value is specified for the timestamp field, the specified value is displayed.
- If no value is specified for the timestamp field, the system time when the message was sent is displayed.
- A value in the 1970/x/x x:x:x format indicates that the timestamp field is set to 0 or an invalid value.
- You cannot specify a value for the timestamp field on ApsaraMQ for Kafka clients of version 0.9 or earlier.
Actions - Click Download Key to download the message key.
- Click Download Value to download the message content.
Important- The ApsaraMQ for Kafka console can display up to 1 KB of content for each message. If the size of a message exceeds 1 KB, the excess content of the message is automatically truncated. If you want to view the complete message content, download the message.
- This operation is supported only by ApsaraMQ for Kafka Professional Edition instances.
- You can download up to 10 MB of messages at a time. If the size of a message exceeds 10 MB, only the first 10 MB of message content can be downloaded.
Query messages by time
You can query messages in all partitions based on a specified point in time. If you do not know the offset of the message that you want to query but know the time range during which the message was sent, you can specify a point in time during the time range to query messages that were sent at and after the specified point in time.
- Log on to the ApsaraMQ for Kafka console.
- In the Resource Distribution section of the Overview page, select the region where your instance is deployed.
- On the Instances page, click the name of the instance that you want to manage.
- In the left-side navigation pane, click Message Query.
- On the Message Query page, select Search by Point in Time from the Search Method drop-down list.
- Select the topic to which the queried message belongs from the Topic drop-down list and the partition to which the queried message belongs from the Partition drop-down list, specify the point in time in the Point in Time box, and then click Search. Messages that were sent at and after the specified point in time are displayed. For information about the parameters that are included in query results, see Parameters in the message query results.The system returns query results based on the value of the Partition parameter.
- If you select All Partitions, messages in all partitions are queried.
- If you specify a partition, messages in the specified partition are queried.