Paginates through all messages in a specified topic within a specified time range.
Operation description
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:
-
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.
-
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
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
mq:QueryMessage |
get |
Topic
Topic
|
None |
|
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:
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.