Updated on 2024-11-14 GMT+08:00

Viewing RocketMQ Messages

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 in the specified topic will be queried. This is exact search and can quickly find a specific message.
  • By message key: The message with the specified message key in the specified topic will be queried. This is exact search and can quickly find a specific message.

Message Deletion Mechanism

Regardless of whether they have been consumed, RocketMQ messages are retained for 48 hours and the upper limit is 720 hours by default. For details about how to modify the retention period, see Changing RocketMQ Message Retention Period. 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% (for v4.8.0) or 75% (for v5.x).
  • 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.

    Message ID is the MsgId returned after the message is produced, for example, the content returned in 6. Message IDs can be recorded in topic queries.

  • To query messages by message key, you need the name of the topic to which the message belongs and the message key.

    Message Key is the message key configured in 7. Message keys can be recorded in topic queries.

Querying the Message Content

  1. Log in to the 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 (only for RocketMQ 4.8.0). 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.

    The message details include the message size, message creation time, and message content.
    Figure 1 Viewing message details

    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.

    Click Copy to copy the message content.