Updated on 2024-01-15 GMT+08:00

Querying Messages

Scenario

This section describes how to view the content of a message and check whether the message is successfully created or retrieved.

On the DMS for RocketMQ console, you can query messages by topic, message ID, or message key.

  • By topic: All messages of a specified topic within a specified period will be queried. This is range query and may find a large number of messages.
  • By message ID: The message with the specified message ID will be queried. This is exact search and can quickly find a specific message.
  • By message key: The message with the specified message key will be queried. This is exact search and can quickly find a specific message.

Message Deletion Mechanism

By default, RocketMQ messages are retained for 48 hours and the upper limit is 720 hours, regardless of whether they have been consumed. RocketMQ messages are stored in CommitLog files. Each CommitLog file is 1 GB. When a CommitLog file is full, a new CommitLog file is generated. Message deletion in RocketMQ means to delete the CommitLog files, instead of individual messages. CommitLog files are written in sequence. A CommitLog file expires when the last message written in it expires. CommitLog files are deleted in the following scenarios:

  • Expired files are cleared at 04:00 every day. Earlier instances that do not have a time zone are cleared at 12:00 every day.
  • Expired files are deleted immediately when the disk usage reaches 70%.
  • The earliest files are deleted, regardless of whether they have expired, when the disk usage reaches 85%.

Prerequisites

  • A RocketMQ instance and topics have been created.
  • To query messages by message ID, you need the name of the topic to which the message belongs and the message ID.
  • To query messages by message key, you need the name of the topic to which the message belongs and the message key.
  • To query message traces, you must first enable message tracing.

Querying the Message Content

  1. Log in to the management console.
  2. Click in the upper left corner to select a region.

    Select the region where your RocketMQ instance is located.

  3. Click and choose Middleware > Distributed Message Service for RocketMQ to open the console of DMS for RocketMQ.
  4. Click a RocketMQ instance to go to the instance details page.
  5. In the navigation pane, choose Message Query.
  6. Query messages in either of the following ways:

    • By topic: Select the topic to be queried from the Topic drop-down list and the queue to the queried from the Queue drop-down list. For Stored, select a time period.
    • By message ID: Select the name of the topic to be queried from the Topic drop-down list, enter the ID of the message to be queried, and click Search.
    • By message key: Select the name of the topic to be queried from the Topic drop-down list, enter the key of the message to be queried, and click Search.

  7. In the row that contains the desired message, click View Details to view the message content.

    If the message body is greater than 4096 bytes, some content may not be displayed on the console. In this case, click Download to view the message body in the downloaded JSON file.

Viewing the Message Trace

  1. Locate the row that contains the message to be queried. Click Message Trace.
  2. View the message trace to check whether the message is successfully produced or consumed.

    Table 1 describes message trace parameters.

    Table 1 Message trace parameters

    Parameter

    Description

    Producer status

    A producer can be in one of the following states:

    • Sent: The message is sent successfully, and the server has successfully stored the message.
    • Committed: The message can be retrieved by consumers.
    • Rollback: The message will be discarded and cannot be retrieved by consumers.
    • Unknown: The status of the message cannot be determined. After a period of time, the server initiates a check request to the producer.

    Creation duration

    Time taken to send the message by the producer.

    Producer address

    IP address and port of the producer.

    Consumer status

    A consumer can be in one of the following states:

    • Retrieved
    • Retrieval timed out
    • Abnormal retrieval
    • NULL returned
    • Retrieval failed

    Retrieved

    Time when the message is retrieved.

    Retrieval duration

    Time taken to retrieve the message by the consumer.

    Consumer address

    IP address and port of the consumer.