Queries messages by conducting a fuzzy search based on a specified topic name and message key.

Usage notes

  • It is a fuzzy search to query messages based on a specified message key. A key may not be unique for a message. Therefore, the returned results may contain multiple messages.
  • This operation is applicable to scenarios where you cannot obtain message IDs. In these scenarios, perform the following steps:

    1. Call this operation to conduct a fuzzy search to query message IDs.

    2. Call the OnsMessageGetByMsgId operation to conduct an exact search. For more information about the OnsMessageGetByMsgId operation, see OnsMessageGetByMsgId.

QPS limit

The queries-per-second (QPS) limit on this operation is 10 per user. Throttling is triggered when the number of calls to this operation per second exceeds the QPS limit. Throttling may affect your business. Therefore, call this operation based on your needs. For more information, see QPS limits.

Authorization information

By default, only Alibaba Cloud accounts can call this operation. RAM users can call this operation only after they are authorized to use it. The following table lists the authorization information of this operation. For more information, see Policies and examples.

API

Action

Resource with a namespace

Resource without a namespace

OnsMessageGetByKey

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.

InstanceId String Yes MQ_INST_111111111111_DOxxxxxx

The ID of the Message Queue for Apache RocketMQ instance that corresponds to the message you want to query.

Key String Yes messageKey1

The key of the message that you want to query.

Topic String Yes test-mq_topic

The topic of the message that you want to query.

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

Response parameters

Parameter Type Example Description
Data Array of OnsRestMessageDo

The query results.

OnsRestMessageDo
BodyCRC Integer 914112295

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

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

The producer instance that produced the message.

BornTimestamp Long 1570760999721

The timestamp that indicates when the message was produced.

InstanceId String MQ_INST_111111111111_DOxxxxxx

The ID of the Message Queue for Apache RocketMQ instance.

MsgId String 1E0578FE110F18B4AAC235C05F2*****

The ID of the message.

PropertyList Array of MessageProperty

A returned list of properties of the message.

MessageProperty
Name String TAGS

The property of the message. Valid values:

  • TRACE_ON: indicates whether a trace of the message exists.

    - KEYS: indicates the key property of the message.

  • TAGS: indicates the tag property of the message.
  • INSTANCE_ID: indicates the ID of the Message Queue for Apache RocketMQ instance that corresponds to the message.

For more information about the terms, see Terms.

Value String TagA

The value of the message property.

ReconsumeTimes Integer 1

The number of consumption retries of the message.

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

The Message Queue for Apache RocketMQ broker that stored the message.

StoreSize Integer 406

The size of the message.

StoreTimestamp Long 1570760999811

The time when the Message Queue for Apache RocketMQ broker stored the message.

Topic String test-mq_topic

The topic of the message.

RequestId String A07E3902-B92E-44A6-B6C5-6AA111111****

The ID of the request, which is a common parameter. Each request has a unique ID to facilitate troubleshooting and fault locating.

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

<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

{
  "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.

Operations in the console

In addition to calling the OnsMessageGetByKey operation, you can query the details of messages in the Message Queue for Apache RocketMQ console. For more information, see Query messages.