Queries the messages that are published to a specified topic within a specified time range by page.

Note

  • If you do not know the message ID or message key of a message that you want to query, you can call this operation to query all messages that are published to a topic within a specified time range. The results are displayed by page.
  • We recommend that you specify a short time range to query messages. If you specify a long time range, a large number of messages are returned. In this case, you need to spend a long period of time to find the message that you want to query. Perform the following steps to query messages:

    1. Specify the Topic, BeginTime, EndTime, and PageSize parameters to query the information about messages in the specified topic. By default, the information about the messages on the first page, total number of pages, and task ID are returned.

    2. Specify the task ID and a page number to call this operation again to query the messages on the specified page. In this query, the BeginTime, EndTime, and PageSize parameters do not take effect. By default, the system uses the values of these parameters that you specified in the request for creating the query task.

Request limit

Each Alibaba Cloud account can call this operation up to 10 times per minute. If the number of requests that you send to call this operation within one minute reaches the request limit, new requests fail. This may interrupt your business. For information about the request limit of each operation, see API request limits.

Authorization

By default, Alibaba Cloud accounts can call this operation. A Resource Access Management (RAM) user can call this operation only after the RAM user is granted the required permissions. The following table describes the permissions that must be granted to a RAM user to call this operation. For information about how to grant permissions, see Policies.

API

Action

Resource in an instance that uses a namespace

Resource in an instance that does not use a namespace

OnsMessagePageQueryByTopic

mq:QueryInstanceBaseInfo

mq:QueryMessage

acs:mq:*:*:{instanceId}%{topic}

acs:mq:*:*:{topic}

Request parameters

Parameter Type Required Example Description
Action String Yes OnsMessagePageQueryByTopic

The operation that you want to perform. Set the value to OnsMessagePageQueryByTopic.

Topic String Yes test-mq_topic

The topic in which the messages you want to query are stored.

BeginTime Long Yes 1570723200000

The beginning of the time range to query. The value is a UNIX timestamp representing the number of milliseconds that have elapsed since the epoch time January 1, 1970, 00:00:00 UTC.

If you specify a valid value for the TaskId parameter in the request, this parameter does not take effect. The system uses the value of the BeginTime parameter that you specified in the request for creating the query task.

EndTime Long Yes 1570809600000

The end of the time range to query. The value is a UNIX timestamp representing the number of milliseconds that have elapsed since the epoch time January 1, 1970, 00:00:00 UTC.

If you specify a valid value for the TaskId parameter in the request, this parameter does not take effect. The system uses the value of the EndTime parameter that you specified in the request for creating the query task.

TaskId String No 0BC1310300002A9F000021E4D7A48346

The ID of the query task. The first time you call this operation to query information about messages that are published to a topic in a specified time range, this parameter is not required. This parameter is required in subsequent queries for messages on a specified page. You can obtain the task ID from the returned result of the first query.

CurrentPage Integer Yes 2

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

PageSize Integer No 5

The number of entries to return on each page. Valid values: 5 to 50. Default value: 20.

If you specify a valid value for the TaskId parameter in the request, this parameter does not take effect. The system uses the value of the PageSize parameter that you specified in the request for creating the query task.

InstanceId String Yes MQ_INST_111111111111_DOxxxxxx

The ID of the Message Queue for Apache RocketMQ instance which contains the topic.

Note For more information about request parameters, see Common parameters and Make API requests.

Response parameters

Parameter Type Example Description
RequestId String 5DC2A47E-2B31-4722-96C8-FA59C9*****

The ID of the request. The system generates a unique ID for each request. You can troubleshoot issues based on the request ID.

MsgFoundDo Object

The information that is returned.

CurrentPage Long 1

The page number of the returned page.

MsgFoundList Array of OnsRestMessageDo

The information about messages on the returned page. The information that is contained in this parameter is the same as the information that is returned by the OnsMessageGetByMsgId operation.

OnsRestMessageDo
StoreSize Integer 406

The size of the message. Unit: KB.

ReconsumeTimes Integer 1

The number of retries that are performed to consume the message.

StoreTimestamp Long 1570760999811

The point in time when the message was published to the Message Queue for Apache RocketMQ broker. The value is a UNIX timestamp representing the number of milliseconds that have elapsed since the epoch time January 1, 1970, 00:00:00 UTC.

InstanceId String MQ_INST_111111111111_DOxxxxxx

The ID of the instance.

MsgId String 1E0578FE110F18B4AAC235C05F2*****

The ID of the message.

StoreHost String 11.193.***.***:10911

The Message Queue for Apache RocketMQ server that stores the message.

Topic String test-mq_topic

The topic in which the message is stored.

PropertyList Array of MessageProperty

The properties of the message.

MessageProperty
Value String TagA

The value of the property.

Name String TAGS

The name of the property. Valid values:

  • TRACE_ON: indicates whether a trace of the message exists.
  • KEYS: indicates the message key of the message.
  • TAGS: indicates the tags of the message.
  • INSTANCE_ID: indicates the ID of the instance which contains the message.

For more information about the terms that are used in Message Queue for Apache RocketMQ, see Terms.

BornTimestamp Long 1570760999721

The point in time when the message was generated. The value is a UNIX timestamp representing the number of milliseconds that have elapsed since the epoch time January 1, 1970, 00:00:00 UTC.

BodyCRC Integer 914112295

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

BornHost String 42.120.***.***:59270

The producer client that generated the message.

MaxPageCount Long 400

The total number of result pages.

TaskId String 0BC1310300002A9F000021E4D7A48346

The ID of the query task. The first time you call this operation to query messages that are published to a topic in a specified time range, this parameter is returned. You can use the task ID to query messages on other returned pages.

Examples

Sample requests

http(s)://ons.cn-hangzhou.aliyuncs.com/?Action=OnsMessagePageQueryByTopic
&BeginTime=1570723200000
&CurrentPage=2
&EndTime=1570809600000
&InstanceId=MQ_INST_111111111111_DOxxxxxx
&Topic=test-mq_topic
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

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

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

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

Error codes

For a list of error codes, visit the API Error Center.

View information about messages in the console

In the Message Queue for Apache RocketMQ console, you can view the information about a message. For more information, see Query a message.