Queries the information about a message by specifying the message ID to determine whether the message is consumed.

Usage notes

  • If a message is not consumed as expected, you can query the message content for troubleshooting.
  • It is an exact search to query a message based on a message ID. The message ID required by the search criteria is obtained from SendResult after a message is sent. Therefore, the producer must store the results of message sending. The information includes properties such as the sending time, Message Queue for Apache RocketMQ broker, message key, and message tag.

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

OnsMessageGetByMsgId

mq:QueryMessage

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

acs:mq:*:*:{topic}

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 OnsMessageGetByMsgId

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

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.

MsgId String Yes 1E0578FE110F18B4AAC235C05F2*****

The ID 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 Struct

The query results.

BodyCRC Integer 914112295

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

BornHost String 42.120.**. **:64646

The producer instance that produced the message.

BornTimestamp Long 1570761026630

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 1E0578FE110F18B4AAC235C0C8460BA2

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.220.***. ***:10911

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

StoreSize Integer 407

The size of the message.

StoreTimestamp Long 1570761026708

The timestamp that indicates 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=OnsMessageGetByMsgId
&InstanceId=MQ_INST_111111111111_DOxxxxxx
&MsgId=1E0578FE110F18B4AAC235C05F2*****
&Topic=test-mq_topic
&<Common request parameters>

Sample success responses

XML format

<OnsMessageGetByMsgIdResponse>
  <Data>
        <MsgId>1E0578FE110F18B4AAC235C0C8460BA2</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>
</OnsMessageGetByMsgIdResponse>

JSON format

{
  "Data": {
    "MsgId": "1E0578FE110F18B4AAC235C0C8460BA2",
    "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 OnsMessageGetByMsgId operation, you can query the details of a message in the Message Queue for Apache RocketMQ console. For more information, see Query messages.