Queries the traces of a device corresponding to a ApsaraMQ for MQTT client by page. When a device is in an abnormal state, you can call this operation to query the connection history of the device. This helps you locate the problem and identify the cause of the problem.

Billing

Each successful call to the QueryMqttTraceDevice 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
ActionStringYesQueryMqttTraceDevice

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

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@@@producer

The client ID of the device whose traces you want to query.

BeginTimeLongYes1621580400000

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.

EndTimeLongYes1621584000000

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.

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 of action on the device. This means that the information about the last action on the device is displayed as the first entry and that the information about the earliest action on the device is displayed as the last entry.
  • false: The returned results are displayed in order of the time of action on the device. This means that the information about the earliest action on the device is displayed as the first entry and that the information about the last action on the device is displayed as the last entry.

The default value : false.

Response parameters

ParameterTypeExampleDescription
RequestIdString317076B7-F946-46BC-A98F-4CF9777C****

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

TotalLong3

The total number of entries returned.

CurrentPageInteger1

The page number of the returned page.

PageSizeInteger2

The number of entries returned per page.

DeviceInfoListArray of DeviceInfoList

The details about an entry.

ActionStringconnect

The action on the device. Valid values:

  • connect: The ApsaraMQ for MQTT client requests a connection to the ApsaraMQ for MQTT broker.
  • close: The TCP connection is closed.
  • disconnect: The ApsaraMQ for MQTT client sends a request to disconnect from the ApsaraMQ for MQTT broker.
ActionCodeStringmqtt.trace.action.connect

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

  • mqtt.trace.action.connect: This parameter value is returned if the value of the Action parameter is connect .
  • mqtt.trace.action.close: This parameter value is returned if the value of the Action parameter is close.
  • mqtt.trace.action.disconnect: This parameter value is returned if the value of the Action parameter is disconnect.
ActionInfoStringaccept

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

  • accepted: The ApsaraMQ for MQTT broker receives the connection request from the ApsaraMQ for MQTT client.
  • not authorized: The TCP connection is closed because the permission verification for the ApsaraMQ for MQTT client to access the instance failed.
  • clientId conflict: The TCP connection is closed due to a conflict in the ID of the ApsaraMQ for MQTT client.
  • resource auth failed: The TCP connection is closed because the permission verification for the ApsaraMQ for MQTT client to access the topic or group ID failed.
  • no heart: The TCP connection is closed due to no heartbeat.
  • closed by client: The TCP connection is closed due to an exception on the ApsaraMQ for MQTT client.
  • disconnected by client: The ApsaraMQ for MQTT client requests a disconnection.
  • invalid param: The TCP connection is closed due to invalid request parameters.
  • Socket IOException: The TCP connection is closed due to network jitter or packet loss.
ChannelIdStringc69fe839209547fa9d073781b9cd****

The ID of a connection.

TimeString2021-05-21 15:51:54.867

The time when the action occurred on the device.

Examples

Sample requests

http(s)://onsmqtt.cn-hangzhou.aliyuncs.com/?Action=QueryMqttTraceDevice
&MqttRegionId=cn-hangzhou
&InstanceId=mqtt-cn-i7m26mf****
&ClientId=GID_test@@@producer
&BeginTime=1621580400000
&EndTime=1621584000000
&CurrentPage=1
&PageSize=5
&Reverse=false
&<Common request parameters>

Sample success responses

XML format

<QueryMqttTraceDeviceResponse>
  <DeviceInfoList>
        <Action>connect</Action>
        <ActionCode>mqtt.trace.action.connect</ActionCode>
        <ActionInfo>accepted</ActionInfo>
        <Time>2021-05-21 15:10:21.844</Time>
        <ChannelId>27e1c09a1d7d4944901500db7186****</ChannelId>
   </DeviceInfoList>
   <DeviceInfoList>
        <Action>close</Action>
        <ActionCode>mqtt.trace.action.close</ActionCode>
        <ActionInfo>no heart</ActionInfo>
        <Time>2021-05-21 15:51:37.980</Time>
        <ChannelId>27e1c09a1d7d4944901500db7186****</ChannelId>
   </DeviceInfoList>
   <DeviceInfoList>
        <Action>connect</Action>
        <ActionCode>mqtt.trace.action.connect</ActionCode>
        <ActionInfo>accepted</ActionInfo>
        <Time>2021-05-21 15:52:48.669</Time>
        <ChannelId>34022074d3c1403faba6e0334121****</ChannelId>
   </DeviceInfoList>
   <PageSize>5</PageSize>
   <CurrentPage>1</CurrentPage>
   <Total>3</Total>
   <RequestId>317076B7-F946-46BC-A98F-4CF9777C****</RequestId>
</QueryMqttTraceDeviceResponse>

JSON format

{
    "DeviceInfoList": [
    {
      "Action": "connect",
      "ActionCode": "mqtt.trace.action.connect",
      "ActionInfo": "accepted",
      "Time": "2021-05-21 15:10:21.844",
      "ChannelId": "27e1c09a1d7d4944901500db7186****"
    },
    {
      "Action": "close",
      "ActionCode": "mqtt.trace.action.close",
      "ActionInfo": "no heart",
      "Time": "2021-05-21 15:51:37.980",
      "ChannelId": "27e1c09a1d7d4944901500db7186****"
    },
    {
      "Action": "connect",
      "ActionCode": "mqtt.trace.action.connect",
      "ActionInfo": "accepted",
      "Time": "2021-05-21 15:52:48.669",
      "ChannelId": "34022074d3c1403faba6e0334121****"
    }
  ],
    "PageSize": 5,
    "CurrentPage": 1,
    "Total": 3,
    "RequestId": "317076B7-F946-46BC-A98F-4CF9777C****"
}

Error codes

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

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

Operations in the ApsaraMQ for MQTT console

In addition to calling the QueryMqttTraceDevice operation, you can also view device traces in the ApsaraMQ for MQTT console. For more information, see Query device traces.