Queries the traces of a device corresponding to a Message Queue 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

Parameter Type Required Example Description
Action String Yes QueryMqttTraceDevice

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

MqttRegionId String Yes cn-hangzhou

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

InstanceId String Yes mqtt-cn-i7m26mf****

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

ClientId String Yes GID_test@@@producer

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

BeginTime Long Yes 1621580400000

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.

EndTime Long Yes 1621584000000

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.

CurrentPage Integer Yes 1

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.

PageSize Integer Yes 5

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

Reverse Boolean Yes false

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.

If this parameter is not specified, the returned results are displayed in order of the time of action on the device by default.

Response parameters

Parameter Type Example Description
RequestId String 317076B7-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.

Total Long 3

The total number of entries returned.

CurrentPage Integer 1

The page number of the returned page.

PageSize Integer 2

The number of entries returned per page.

DeviceInfoList Array of DeviceInfoList

The details about an entry.

Action String connect

The action on the device. Valid values:

  • connect: The Message Queue for MQTT client requests a connection to the Message Queue for MQTT broker.
  • close: The TCP connection is closed.
  • disconnect: The Message Queue for MQTT client sends a request to disconnect from the Message Queue for MQTT broker.
ActionCode String mqtt.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.
ActionInfo String accept

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

  • accepted: The Message Queue for MQTT broker receives the connection request from the Message Queue for MQTT client.
  • not authorized: The TCP connection is closed because the permission verification for the Message Queue for MQTT client to access the instance failed.
  • clientId conflict: The TCP connection is closed due to a conflict in the ID of the Message Queue for MQTT client.
  • resource auth failed: The TCP connection is closed because the permission verification for the Message Queue 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 Message Queue for MQTT client.
  • disconnected by client: The Message Queue 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.
ChannelId String c69fe839209547fa9d073781b9cd****

The ID of a connection.

Time String 2021-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

HttpCode Error code Error message Description
500 SystemOverFlow An error occurred while processing your request. Please try again. The error message returned because throttling is triggered by the system. Try again later.
404 ApiNotSupport The 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 Message Queue for MQTT console

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