You can call this operation to query messages based on a specified topic name and message key.

It is a fuzzy search to query messages by a specified message key. A key may not be unique for a message, therefore multiple messages may be contained in the returned results.

This operation is applicable to scenarios where you cannot obtain the message ID. The procedure for calling the operation is as follows:

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

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

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

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 corresponding to the messages that you want to query.

Key String Yes messageKey1

The key of the messages that you want to query.

Topic String Yes test-mq_topic

The topic of the messages that you want to query.

Response parameters

Parameter Type Example Description
Data Array

The returned query results.

OnsRestMessageDo
Body String SGVsbG8gTVEg5raT7oWf5p6D5ai05ayt55iv

The body of the message.

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 indicating when the message was produced.

InstanceId String MQ_INST_111111111111_DOxxxxxx

The ID of the Message Queue for Apache RocketMQ instance corresponding to the message.

MsgId String 1E0578FE110F18B4AAC235C05F2*****

The ID of the message.

PropertyList Array

A returned list of properties of the message.

MessageProperty
Name String TAGS

The property of the message. Valid values:

  • TRACE_ON: indicates whether any trace of the message exists.
  • KEYS: the key property of the message.
  • TAGS: the tag property of the message.
  • INSTANCE_ID: the ID of the Message Queue for Apache RocketMQ instance corresponding 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 timestamp indicating when the Message Queue for Apache RocketMQ broker stored the message.

Topic String test-mq_topic

The topic of the message.

RequestId String 5DC2A47E-2B31-4722-96C8-FA59C996F0CA

The ID of the request. This is a common parameter.

Examples

Sample requests

http(s)://[Endpoint]/? 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>
        <Body>SGVsbG8gTVEg5raT7oWf5p6D5ai05ayt55iv</Body>
        <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-6AA1111111799</RequestId>
</OnsMessageGetByKeyResponse>

JSON format

{
  "Data": {
    "MsgId": "1E0578FE110F18B4AAC235C05F2*****",
    "Body": "SGVsbG8gTVEg5raT7oWf5p6D5ai05ayt55iv",
    "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-6AA1111111799"
}

Error codes

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