You can call this operation to query the number of sent and received messages based on information such as topics.


OnsMqttQueryMsgTransTrend is typically used to generate data reports and service statistics.


API operations are designed for you to implement custom management and development. Based on this, the Message Queue for MQTT broker throttles frequent calls that amount to 30 or more per minute. Therefore, do not call this operation in the main service process. To determine whether a Message Queue for MQTT client is connected, use the device online/offline notification function. If a Message Queue for MQTT client is online, this client has been connected to a Message Queue for MQTT broker.


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 OnsMqttQueryMsgTransTrend

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

BeginTime Long Yes 1570957261

The beginning of the time range to query.

EndTime Long Yes 1570962601

The end of the time range to query. We recommend that the start time and end time of a query fall on the same day. If the time range for a query exceeds this time limit, the backend automatically returns query results that only correspond to this time limit.

InstanceId String Yes post-cn-0pp12gl****

The ID of the Message Queue for MQTT instance whose statistics you want to query. This parameter is required for instances with separate namespaces.

ParentTopic String Yes test

The parent topic that you want to query.

TpsType String Yes TPS

Specifies whether to query the TPS or SUM. Valid values:

  • TPS: message production TPS
  • SUM: message production volume

Other values are invalid.

TransType String Yes PUB

Specifies whether to query the production or consumption report. Valid values:

  • PUB: message production report
  • SUB: message consumption report

Other values are invalid.

SubTopic String No /testMq4Iot

The subtopic that you want to query. This parameter can be blank if no subtopic exists or if you want to query all the information about the parent topic.

MsgType String No P2P

The message type. Valid values:

  • P2P: point to point
  • SUB: publish/subscribe

By default, all messages are queried if this parameter is not set. Other values are invalid.

Qos Integer No 0

The quality of service (QoS) level of the messages to be queried. Valid values:

  • 0: The message is sent at most once.
  • 1: The message is received at least once.
  • 2: The message is sent exactly once.

By default, all messages are queried if this parameter is set to other values or is not set. For more information about QoS, see Terms.

Response parameters

Parameter Type Example Description
Data Struct

The returned data set.

Records Array

The data set that includes more detailed information.

X Long 1570960800

The X axis, which represents time in the timestamp format. Unit: millisecond.

Y Float 3

The Y axis, which represents the TPS or the message production volume.

Title String Message production TPS

The name of the table that lists the historical message production TPS or volume in the specified time range.

XUnit String Time

The time in the X axis, which is in the timestamp format. Unit: millisecond.

YUnit String Messages/second

The unit of the Y axis.

RequestId String 77B5727C-CCDF-4404-B7A0-EC0D3CF4BEDE

The ID of the request, which is a common parameter. Each request has a unique ID to facilitate troubleshooting and fault locating.


Sample requests

http(s)://[Endpoint]/? Action=OnsMqttQueryMsgTransTrend
&<Common request parameters>

Sample success responses

XML format

        <Title>Message production TPS</Title>

JSON format

	"Data": {
		"Records": {
			"StatsDataDo": [{"X": "1570960800",
            "Y": "3"}]
		"XUnit": "Time",
		"YUnit": "Messages/second",
		"Title": "Message production TPS"
	"RequestId": "77B5727C-CCDF-4404-B7A0-EC0D3CF4BEDE"

Error codes

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