All Products
Search
Document Center

ApsaraMQ for RocketMQ:OnsMessagePageQueryByTopic

Last Updated:Aug 28, 2026

Paginates through all messages in a specified topic within a specified time range.

Operation description

Note

Alibaba Cloud OpenAPI operations are designed for management and query purposes only. Do not use them in the core data path of messaging services. Otherwise, system risks may occur.

  • Call this operation to query all messages in a topic within a specified time range when you do not know the message ID or key. Results are returned by page.

  • Specify a short time range for efficient querying. A long time range returns too many messages to browse efficiently. Query messages as follows:

    1. Specify the topic, start time, end time, and page size. The response returns the first page of messages, total page count, and a task ID.

    2. Specify the task ID and a page number to retrieve subsequent pages. The BeginTime, EndTime, and PageSize parameters are ignored because the system reuses the values from the initial query task.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

mq:QueryMessage

get

Topic

acs:mq:{#regionId}:{#accountId}:{#TopicName}

Topic

acs:mq:{#regionId}:{#accountId}:{#InstanceId}%{#TopicName}

None
  • mq:OnsInstanceBaseInfo

Request parameters

Parameter

Type

Required

Description

Example

Topic

string

Yes

The name of the topic whose messages you want to query.

test-mq_topic

BeginTime

integer

Yes

The start of the time range to query. Value: a UNIX timestamp in milliseconds. Ignored when TaskId is specified; the system reuses the BeginTime from the initial query task.

1570723200000

EndTime

integer

Yes

The end of the time range to query. Value: a UNIX timestamp in milliseconds. Ignored when TaskId is specified; the system reuses the EndTime from the initial query task.

1570809600000

TaskId

string

No

The query task ID. Not required for the first call. Required for subsequent page queries. Obtain this value from the response of the first query.

0BC1310300002A9F000021E4D7A48346

CurrentPage

integer

Yes

The number of the page to return. Pages start from page 1. Valid values: 1 to 50.

2

PageSize

integer

No

The number of entries per page. Valid values: 5 to 50. Default value: 20. Ignored when TaskId is specified; the system reuses the PageSize from the initial query task.

5

InstanceId

string

No

The ID of the instance that contains the target message.

MQ_INST_111111111111_DOxxxxxx

Response elements

Element

Type

Description

Example

object

The data returned.

RequestId

string

The request ID. Use this ID to troubleshoot issues.

5DC2A47E-2B31-4722-96C8-FA59C9*****

MsgFoundDo

object

The information about the message that is queried.

CurrentPage

integer

The page number of the returned page.

1

MsgFoundList

object

OnsRestMessageDo

array<object>

The messages on the current page. Fields are identical to those returned by OnsMessageGetByMsgId.

array<object>

StoreSize

integer

The size of the message. Unit: KB.

406

ReconsumeTimes

integer

The number of consumption retries for this message.

1

StoreTimestamp

integer

The time when the broker stored the message. Value: a UNIX timestamp in milliseconds.

1570760999811

InstanceId

string

The ID of the instance

MQ_INST_111111111111_DOxxxxxx

MsgId

string

The ID of the message.

1E0578FE110F18B4AAC235C05F2*****

StoreHost

string

The ApsaraMQ for RocketMQ broker that stores the message.

11.193.***.***:10911

Topic

string

The topic to which the message belongs.

test-mq_topic

PropertyList

object

MessageProperty

array<object>

The attributes of the message.

object

Value

string

The value of the attribute.

TagA

Name

string

The property name. Valid values:

  • TRACE_ON: whether a message trace exists.

  • KEYS: the message key.

  • TAGS: the message tag.

  • INSTANCE_ID: the ID of the instance that contains the message.

ApsaraMQ for RocketMQ Terms.

TAGS

BornTimestamp

integer

The time when the producer generated the message. Value: a UNIX timestamp in milliseconds.

1570760999721

BodyCRC

integer

The cyclic redundancy check (CRC) value of the message body.

914112295

BornHost

string

The producer client that generated the message.

42.120.***.***:59270

MaxPageCount

integer

The total number of returned pages.

400

TaskId

string

The query task ID. Returned on the first call. Use this ID to retrieve subsequent pages.

0BC1310300002A9F000021E4D7A48346

Examples

Success response

JSON format

{
  "RequestId": "5DC2A47E-2B31-4722-96C8-FA59C9*****",
  "MsgFoundDo": {
    "CurrentPage": 1,
    "MsgFoundList": {
      "OnsRestMessageDo": [
        {
          "StoreSize": 406,
          "ReconsumeTimes": 1,
          "StoreTimestamp": 1570760999811,
          "InstanceId": "MQ_INST_111111111111_DOxxxxxx",
          "MsgId": "1E0578FE110F18B4AAC235C05F2*****",
          "StoreHost": "11.193.***.***:10911",
          "Topic": "test-mq_topic",
          "PropertyList": {
            "MessageProperty": [
              {
                "Value": "TagA",
                "Name": "TAGS"
              }
            ]
          },
          "BornTimestamp": 1570760999721,
          "BodyCRC": 914112295,
          "BornHost": "42.120.***.***:59270"
        }
      ]
    },
    "MaxPageCount": 400,
    "TaskId": "0BC1310300002A9F000021E4D7A48346"
  }
}

Error codes

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.