Creates a task to query the trace of a message based on the message key and the name of the topic in which the message is stored. This operation returns the ID of the query task.

Usage notes

If you obtain the key of a message and want to query the trace of the message, you can call this operation to create a query task. After you obtain the task ID, you can call the OnsTraceGetResult operation to query the details of the message trace based on the task ID.

Request limit

Each Alibaba Cloud account can call this operation up to 30 times per minute. If the number of requests that you send to call this operation within 1 minute reaches the request limit, new requests fail. This may interrupt your business. For information about the request limit of each operation, see API rate limits.

Authorization

By default, only 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, Policies and examples.

API

Action

Resource in an instance that uses a namespace

Resource in an instance that does not use a namespace

OnsTraceQueryByMsgKey

mq:QueryInstanceBaseInfo

mq:QueryTrace

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

acs:mq:*:*:{topic}

Request parameters

Parameter Type Required Example Description
Action String Yes OnsTraceQueryByMsgKey

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

Topic String Yes test

The topic in which the message you want to query is stored.

MsgKey String Yes ORDERID_100

The key of the message that you want to query.

BeginTime Long Yes 1570852800000

The beginning of the time range to query. Set the value to a UNIX timestamp that represents the number of milliseconds that have elapsed since the epoch time January 1, 1970, 00:00:00 UTC.

EndTime Long Yes 1570968000000

The end of the time range to query. Set the value to a UNIX timestamp that represents the number of milliseconds that have elapsed since the epoch time January 1, 1970, 00:00:00 UTC.

InstanceId String Yes MQ_INST_111111111111_DOxxxxxx

The ID of the Message Queue for Apache RocketMQ instance that contains the specified topic.

Response parameters

Parameter Type Example Description
RequestId String F8654231-122A-4DBD-801F-38E35538****

The ID of the request. The system generates a unique ID for each request. You can troubleshoot issues based on the request ID.

QueryId String 272967562652883649157096685****

The ID of the query task. You can call the OnsTraceGetResult operation to query the details of the message trace based on the task ID.

Examples

Sample requests

http(s)://ons.cn-hangzhou.aliyuncs.com/?Action=OnsTraceQueryByMsgKey
&BeginTime=1570852800000
&EndTime=1570968000000
&InstanceId=MQ_INST_111111111111_DOxxxxxx
&MsgKey=ORDERID_100
&Topic=test
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<OnsTraceQueryByMsgKeyResponse>
<RequestId>F8654231-122A-4DBD-801F-38E35538****</RequestId>
<QueryId>272967562652883649157096685****</QueryId>
</OnsTraceQueryByMsgKeyResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "F8654231-122A-4DBD-801F-38E35538****",
  "QueryId" : "272967562652883649157096685****"
}

Error codes

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

Query the trace of a message in the console

You can also create a task to query the trace of a message in the Message Queue for Apache RocketMQ console. For more information, see Query a message.