Queries the information about messages based on a message key.
Note
- This operation uses the fuzzy match method to query messages based on a specified message key. The same message key may be used by multiple messages. Therefore, the returned result may contain the information about multiple messages.
-
This operation can be used in scenarios in which you cannot obtain the ID of the message you want to query. You can perform the following steps to query the information about a message:
1. Call this operation to obtain the ID of the message.
2. Call the OnsMessageGetByMsgId operation to query the details of the message. For more information about the OnsMessageGetByMsgId operation, see OnsMessageGetByMsgId.
Request limit
Each Alibaba Cloud account can call this operation up to 10 times per second. If the number of requests that you send to call this operation within one second 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 |
---|---|---|---|
OnsMessageGetByKey |
mq:QueryInstanceBaseInfo mq:QueryMessage |
acs:mq:*:*:{instanceId}%{topic} |
acs:mq:*:*:{topic} |
Request parameters
Parameter | Type | Required | Example | Description |
---|---|---|---|---|
Action | String | Yes | OnsMessageGetByKey |
The operation that you want to perform. Set the value to OnsMessageGetByKey. |
Topic | String | Yes | test-mq_topic |
The topic in which the message you want to query is stored. |
Key | String | Yes | messageKey1 |
The key of the message that you want to query. |
InstanceId | String | Yes | MQ_INST_111111111111_DOxxxxxx |
The ID of the Message Queue for Apache RocketMQ instance which contains the message. |
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
RequestId | String | A07E3902-B92E-44A6-B6C5-6AA111111**** |
The ID of the request. The system generates a unique ID for each request. You can troubleshoot issues based on the request ID. |
Data | Array of OnsRestMessageDo |
The data that is returned. |
|
OnsRestMessageDo | |||
StoreSize | Integer | 406 |
The size of the message. |
ReconsumeTimes | Integer | 1 |
The number of retries that the Message Queue for Apache RocketMQ broker performs to send the message to consumers. |
StoreTimestamp | Long | 1570760999811 |
The timestamp when the Message Queue for Apache RocketMQ broker stored the message. |
InstanceId | String | MQ_INST_111111111111_DOxxxxxx |
The ID of the Message Queue for Apache RocketMQ instance which contains the message. |
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:
For more information about the terms that are used in Message Queue for Apache RocketMQ, see Terms. |
BornTimestamp | Long | 1570760999721 |
The timestamp when the message was produced. |
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. |
Examples
Sample requests
http(s)://ons.cn-hangzhou.aliyuncs.com/?Action=OnsMessageGetByKey
&InstanceId=MQ_INST_111111111111_DOxxxxxx
&Key=messageKey1
&Topic=test-mq_topic
&<Common request parameters>
Sample success responses
XML
format
HTTP/1.1 200 OK
Content-Type:application/xml
<OnsMessageGetByKeyResponse>
<Data>
<MsgId>1E0578FE110F18B4AAC235C05F2*****</MsgId>
<InstanceId>MQ_INST_111111111111_DOxxxxxx</InstanceId>
<ReconsumeTimes>1</ReconsumeTimes>
<BornHost>42.120.**.**:64646</BornHost>
<BodyCRC>914112295</BodyCRC>
<StoreHost>11.220.***.***:10911</StoreHost>
<StoreTimestamp>1570761026708</StoreTimestamp>
<BornTimestamp>1570761026630</BornTimestamp>
<Topic>test-mq_topic</Topic>
<StoreSize>407</StoreSize>
<PropertyList>
<MessageProperty>
<Name>TAGS</Name>
<Value>TagA</Value>
</MessageProperty>
</PropertyList>
</Data>
<RequestId>A07E3902-B92E-44A6-B6C5-6AA111111****</RequestId>
</OnsMessageGetByKeyResponse>
JSON
format
HTTP/1.1 200 OK
Content-Type:application/json
{
"Data" : {
"MsgId" : "1E0578FE110F18B4AAC235C05F2*****",
"InstanceId" : "MQ_INST_111111111111_DOxxxxxx",
"ReconsumeTimes" : 1,
"BornHost" : "42.120.**.**:64646",
"BodyCRC" : 914112295,
"StoreHost" : "11.220.***.***:10911",
"StoreTimestamp" : 1570761026708,
"BornTimestamp" : 1570761026630,
"Topic" : "test-mq_topic",
"StoreSize" : 407,
"PropertyList" : {
"MessageProperty" : [ {
"Name" : "TAGS",
"Value" : "TagA"
} ]
}
},
"RequestId" : "A07E3902-B92E-44A6-B6C5-6AA111111****"
}
Error codes
For a list of error codes, visit the API Error Center.
Query the information about a message in the console
In the Message Queue for Apache RocketMQ console, you can query the information about a message. For more information, see Query a message.