Queries the delivery traces of a specified message. If a message is not sent and received as expected, you can call this operation to view the details about the message. For example, you can query the clients that subscribe to the message and the time when the message is delivered. This operation helps you locate the problem and identify the cause of the problem.

Billing

Each successful call to the QueryMqttTraceMessageSubscribe operation increases the messaging transaction per second (TPS) by one. Therefore, you are charged for the call. For more information about the billing details, see Billing.

QPS limit

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

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

ParameterTypeRequiredExampleDescription
ActionStringYesQueryMqttTraceMessageSubscribe

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

MqttRegionIdStringYescn-hangzhou

The region ID of the ApsaraMQ for MQTT instance. For more information, see Endpoints.

InstanceIdStringYesmqtt-cn-i7m26mf****

The ID of the ApsaraMQ for MQTT instance. The value must be the instance ID used on the ApsaraMQ for MQTT client. You can view the instance ID in the Basic Information section on the Instance Details page of the instance in the ApsaraMQ for MQTT console.

ClientIdStringYesGID_test@@@consumer

The ID of the client that subscribes to the message. If this parameter is not specified, the IDs of all the clients that subscribe to the message are returned.

MsgIdStringYesAC1EC1B33D5978308DB17F3245E4****

The ID of the message.

EndTimeLongYes1618646400000

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

BeginTimeLongYes1621936800000

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

CurrentPageIntegerYes1

The number of the page to return. Pages start from page 1. If the input parameter value is greater than the total number of pages, the returned result is empty.

PageSizeIntegerYes5

The number of entries to return on each page. Valid values: 1 to 100.

ReverseBooleanYesfalse

Specifies whether the returned results are displayed in reverse chronological order. Valid values:

  • true: The returned results are displayed in reverse order of the time when the message is delivered. This means that the last consumed message is displayed as the first entry and that the earliest consumed message is displayed as the last entry.
  • false: The returned results are displayed in order of the time when the message is delivered. This means that the earliest consumed message is displayed as the first entry and that the last consumed message is displayed as the last entry.

If this parameter is not specified, the returned results are displayed in order of the time when the message is delivered.

Response parameters

ParameterTypeExampleDescription
RequestIdString4E685844-ADAF-4D85-9EAC-F9471E8C****

The ID of the request. This parameter is a common parameter. Each request has a unique ID, which facilitates troubleshooting and problem locating.

TotalLong2

The total number of delivery traces returned.

CurrentPageInteger1

The page number of the returned page.

PageSizeInteger5

The number of entries to return on each page.

MessageTraceListsArray of MessageTraceLists

The delivery traces of the message queried.

ActionStringsub

The action on the message. Valid values:

  • sub: The ApsaraMQ for MQTT client subscribes to the message.
  • push_offline: The ApsaraMQ for MQTT broker pushes the offline message to the ApsaraMQ for MQTT client.
ActionCodeStringmqtt.trace.action.msg.sub

The code returned for the action on the message. Valid values:

  • mqtt.trace.action.msg.sub: This parameter value is returned if the value of the Action parameter is sub.
  • mqtt.trace.action.msg.push.offline: This parameter value is returned if the value of the Action parameter is push_offline.
ActionInfoStringPush To Mqtt Client

The information returned for the action on the message. Valid values:

  • Push To Mqtt Client: This parameter value is returned if the value of the Action parameter is sub.
  • Push Offline Msg To Mqtt Client: This parameter value is returned if the value of the Action parameter is push_offline.
ClientIdStringGID_test@@@consumer

The ID of the client that subscribes the message.

MsgIdStringAC1EC1B33D5978308DB17F3245E4****

The ID of the message.

TimeString2021-05-25 16:46:41.274

The time when the message was delivered.

Examples

Sample requests

http(s)://onsmqtt.cn-hangzhou.aliyuncs.com/?Action=QueryMqttTraceMessageSubscribe
&MqttRegionId=cn-hangzhou
&InstanceId=mqtt-cn-i7m26mf****
&ClientId=GID_test@@@consumer
&MsgId=AC1EC1B33D5978308DB17F3245E4****
&EndTime=1618646400000
&BeginTime=1621936800000
&CurrentPage=1
&PageSize=5
&Reverse=false
&<Common request parameters>

Sample success responses

XML format

<QueryMqttTraceMessageSubscribeResponse>
    <MessageTraceLists>
        <Action>sub</Action>
        <ActionCode>mqtt.trace.action.msg.sub</ActionCode>
        <ClientId>GID_test@@@consumer</ClientId>
        <ActionInfo>Push To Mqtt Client</ActionInfo>
        <Time>2021-05-25 16:46:41.274 </Time>
        <MsgId>AC1EC1B33D5978308DB17F3245E4****</MsgId>
    </MessageTraceLists>
    <MessageTraceLists>
        <Action>sub</Action>
        <ActionCode>mqtt.trace.action.msg.sub</ActionCode>
        <ClientId>GID_test@@@consumer2</ClientId>
        <ActionInfo>Push To Mqtt Client</ActionInfo>
        <Time>2021-05-25 16:46:41.247 </Time>
        <MsgId>AC1EC1B33D5978308DB17F3245E4****</MsgId>
    </MessageTraceLists>
    <RequestId>4E685844-ADAF-4D85-9EAC-F9471E8C****</RequestId>
    <PageSize>5</PageSize>
    <CurrentPage>1</CurrentPage>
    <Total>2</Total>
</QueryMqttTraceMessageSubscribeResponse>

JSON format

{
        "MessageTraceLists": [
            {
                "Action": "sub",
                "ActionCode": "mqtt.trace.action.msg.sub",
                "ClientId": "GID_test@@@consumer",
                "ActionInfo": "Push To Mqtt Client",
                "Time": "2021-05-25 16:46:41.274",
                "MsgId": "AC1EC1B33D5978308DB17F3245E4****"
            },
            {
                "Action": "sub",
                "ActionCode": "mqtt.trace.action.msg.sub",
                "ClientId": "GID_test@@@consumer2",
                "ActionInfo": "Push To Mqtt Client",
                "Time": "2021-05-25 16:46:41.247",
                "MsgId": "AC1EC1B33D5978308DB17F3245E4****"
            }
        ],
        "RequestId": "4E685844-ADAF-4D85-9EAC-F9471E8C****",
        "PageSize": 5,
        "CurrentPage": 1,
        "Total": 2
}

Error codes

HttpCodeError codeError messageDescription
404ApiNotSupportThe specified API operation is not supported.The error message returned because the API operation is not supported.
500SystemOverFlowAn error occurred while processing your request. Please try again.The error message returned because throttling is triggered by the system. Try again later.

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

Operations in the ApsaraMQ for MQTT console

In addition to calling the QueryMqttTraceMessageSubscribe operation, you can also view the delivery traces of a message in the ApsaraMQ for MQTT console. For more information, see Query message traces.