If an error occurs when a consumer consumes messages, you can troubleshoot the error by querying the messages. In the Message Queue for Apache 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 consumer offset of the message and the ID of the partition where the message is stored in the topic, we recommend that you query messages by offset. For more information about consumer offsets, see Terms.
  • If you do not know the consumer offset of the message but know when the message was sent, we recommend that you query messages by time.

Usage notes

  • In the Message Queue for Apache 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 also related to the following message cleanup policies of Message Queue for Apache Kafka:
    • If the disk usage is lower than 85%, messages whose retention period expires are deleted at 04:00 every day.
    • If the disk usage reaches 85%, messages whose retention period expires are immediately deleted.
    • If the disk usage reaches 90%, messages are deleted from the earliest one stored in the Message Queue for Apache Kafka broker, no matter whether their retention period expires.
    Notice At least one storage file is retained by Message Queue for Apache Kafka when messages are deleted. Therefore, when you query messages, the query results may contain messages whose retention period expires.

Query messages by offset

  1. Log on to the Message Queue for Apache Kafka console.
  2. In the Resource Distribution section of the Overview page, select the region where your instance resides.
  3. On the Instances page, click the name of the instance that you want to manage.
  4. In the left-side navigation pane, click Message Query.
  5. On the Message Query page, select Search by offset from the Search Method drop-down list.
  6. Select a topic name from the Topic drop-down list and a partition from the Partition drop-down list, enter an offset in the Offset field, and then click Search.

    Messages that start from the specified offset are displayed. For example, if the specified partition and offset are both 5, the query results are messages that start from Offset 5 in Partition 5.

    Table 1. Parameters in the query results and supported operations
    GUI element Description
    Partition The ID of the partition in the topic to which the message is sent.
    Offset The offset of the message.
    Key The key of the message. The key is converted to a string.
    Value The value of the message. The value is converted to a string, which indicates the message content.
    Created At The timestamp recorded by the producer when the message is sent or the value of the timestamp field that you specify for the ProducerRecord object.
    Note
    • If a value is specified for the timestamp field, the value is displayed.
    • If no value is specified for the timestamp field, the system time when the message is sent is displayed.
    • A value in the format of 1970/x/x x:x:x indicates that the timestamp field is set to 0 or an invalid value.
    • You cannot specify a value for the timestamp field on clients of Message Queue for Apache Kafka version 0.9 and earlier.
    Actions
    • Click Download Key: Download the key of the message.
    • Click Download Value: Download the content of the message.
    Notice
    • The Message Queue for Apache Kafka console displays a maximum of 1 KB of content for each queried message. The remaining content of the message is omitted. If you need to view the complete message, download the message.
    • This operation is supported only by instances of Professional Edition.
    • You can download up to 10 MB of messages at a time. If the total size of the queried messages 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 by time. If you do not know the message offset but know the time range in which the messages are sent, you can query the messages by time. You can specify a point in time in the time range to query messages that are sent near this point.

  1. Log on to the Message Queue for Apache Kafka console.
  2. In the Resource Distribution section of the Overview page, select the region where your instance resides.
  3. On the Instances page, click the name of the instance that you want to manage.
  4. In the left-side navigation pane, click Message Query.
  5. On the Message Query page, select Search by Point in Time from the Search Method drop-down list.
  6. Select a topic name from the Topic drop-down list and a partition from the Partition drop-down list, specify a point in time in the Point in Time section, and then click Search.
    Messages that are sent at or after the specified point in time are displayed. For information about the parameters in the query results, see Table 1.
    The selected value of the Partition parameter determines the query results.
    • If you select All Partitions, the messages in all partitions are displayed.
    • If you specify a partition, the messages in the specified partition are displayed.