All Products
Search
Document Center

ApsaraMQ for MQTT:QueryMqttTraceDevice

Last Updated:Aug 25, 2026

Queries the device trace of an ApsaraMQ for MQTT client by paging. When a device encounters an exception, you can call this operation to query the connection history of the specified device to help you quickly identify the cause of the exception.

Operation description

  • Each successful call to the QueryMqttTraceDevice operation counts as one message TPS, which affects your billing. For more information about billing, see Billing.

  • The queries per second (QPS) limit for a single user on this operation is 500. Exceeding this limit will trigger throttling, which may affect your business. Call this operation appropriately. For more information, see QPS limits.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

mq:QueryMqttDeviceTrace

none

*Instance

acs:mq:{#regionId}:{#accountId}:{#InstanceId}

None None

Request parameters

Parameter

Type

Required

Description

Example

MqttRegionId

string

Yes

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

cn-hangzhou

InstanceId

string

Yes

The ID of the ApsaraMQ for MQTT instance. This value must match the instance ID that the client actually uses. You can view the instance ID in the Basic Information area on the Instance Details page in the console.

mqtt-cn-i7m26mf****

Reverse

boolean

No

Specifies whether to display the results in reverse chronological order. Valid values:

  • true: Results are displayed in reverse chronological order of device activity time. The most recent device activity is displayed first, and the earliest device activity is displayed last.

  • false: Results are displayed in chronological order of device activity time. The earliest device activity is displayed first, and the most recent device activity is displayed last.

If this parameter is not specified, results are displayed in chronological order by default.

false

ClientId

string

Yes

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

GID_test@@@producer

BeginTime

integer

Yes

The beginning of the time range to query. Unit: milliseconds.

1621580400000

EndTime

integer

Yes

The end of the time range to query. Unit: milliseconds.

1621584000000

CurrentPage

integer

Yes

The number of the page to return. Pages start from page 1. If the value of this parameter exceeds the total number of pages, an empty result is returned.

1

PageSize

integer

Yes

The maximum number of MSMQ to display on each page for paging. Minimum value: 1. Maximum value: 100.

5

Response elements

Element

Type

Description

Example

object

CurrentPage

integer

The current page number.

1

RequestId

string

A common parameter. Each request has a unique ID that is active for troubleshooting and locating issues.

317076B7-F946-46BC-A98F-4CF9777C****

PageSize

integer

The maximum number of device activity entries displayed per page.

2

Total

integer

The total number of device activity entries returned.

3

DeviceInfoList

array<object>

The details of the device activity entries.

object

ChannelId

string

The connection identifier of the device.

c69fe839209547fa9d073781b9cd****

Time

string

The time when the device action occurred.

2021-05-21 15:51:54.867

ActionCode

string

The return code of the device action. Valid values:

  • mqtt.trace.action.connect: returned when the device action is connect.

  • mqtt.trace.action.close: returned when the device action is close.

  • mqtt.trace.action.disconnect: returned when the device action is disconnect.

mqtt.trace.action.connect

Action

string

The device action. Valid values:

  • connect: The client requests a connection to the server.

  • close: The TCP connection is closed.

  • disconnect: The client requests to disconnect from the server.

connect

ActionInfo

string

The description of the device action. Valid values:

  • accepted: The server accepts the connection request from the client.

  • not authorized: The TCP connection is closed because the permission verification of the instance accessed by the client fails.

  • clientId conflict: The TCP connection is closed because of a client ID conflict.

  • resource auth failed: The TCP connection is closed because the permission verification of the topic or group ID resource accessed by the client fails.

  • no heart: The TCP connection is closed because no heartbeat is detected from the client.

  • closed by client: The TCP connection is closed because of a client exception.

  • disconnected by client: The client requests to disconnect.

  • invalid param: The TCP connection is closed because of invalid request parameters.

  • Socket IOException: The TCP connection is closed because of network jitter or packet loss.

accept

Examples

Success response

JSON format

{
  "CurrentPage": 1,
  "RequestId": "317076B7-F946-46BC-A98F-4CF9777C****",
  "PageSize": 2,
  "Total": 3,
  "DeviceInfoList": [
    {
      "ChannelId": "c69fe839209547fa9d073781b9cd****",
      "Time": "2021-05-21 15:51:54.867",
      "ActionCode": "mqtt.trace.action.connect",
      "Action": "connect",
      "ActionInfo": "accept"
    }
  ]
}

Error codes

HTTP status code

Error code

Error message

Description

400 MqttOwnerCheckError Failed to validate the instance permission
400 MqttInstanceNotFound Specified instance is not found
500 SystemOverFlow An error occurred while processing your request. Please try again.
404 ApiNotSupport The specified API is not supported.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.