All Products
Search
Document Center

ApsaraMQ for MQTT:Interfaces and parameters

Last Updated:May 29, 2025

This topic describes the interfaces that are provided by ApsaraMQ for MQTT cloud SDK for Java and the relevant parameters.

Usage notes

  • You can configure common parameters and network parameters in the ChannelConfig.class file. The ChannelConfig.class file is stored in the server-sdk-{SDK Version}\com\alibaba\mqtt\server\config path. When you specify the path, replace {SDK Version} with the version number of the cloud SDK for Java that you use. For information about how to download the cloud SDK for Java, see Release notes.

  • In most cases, the default values of the network parameters are used. If you need to change the values, configure the network parameters based on the network status.

Common parameters

Parameter

Description

domain

The endpoint of your ApsaraMQ for MQTT instance. A Message Queue for MQTT client uses an endpoint of a Message Queue for MQTT instance to connect to the ApsaraMQ for MQTT broker.

When you use a cloud SDK to connect a backend service application to ApsaraMQ for MQTT, specify the endpoint in one of the following formats:

Important

For information about regions that support access using cloud SDKs, see SDK access regions.

  • Public Endpoint: ID of the ApsaraMQ for MQTT instance-server-internet.mqtt.aliyuncs.com

  • VPC Endpoint: ID of the ApsaraMQ for MQTT instance-server-internal.mqtt.aliyuncs.com

You can view the ID of the Message Queue for MQTT instance in the Basic Information section of the Instance Details page in the ApsaraMQ for MQTT console.

port

The port that is used by the cloud SDK for Java. The protocol and port that are used by the cloud SDK must match. Set the value to 5672.

instanceId

The ID of the instance that you created in the ApsaraMQ for MQTT console. You can view the instance ID on the Instance Details page of the ApsaraMQ for MQTT console.

accessKey

The AccessKey ID that you created in the Resource Access Management (RAM) console for identity authentication. For information about how to obtain your AccessKey ID, see Obtain an AccessKey pair.

secretKey

The AccessKey secret that you created in the RAM console for identity authentication. For information about how to obtain your AccessKey secret, see Obtain an AccessKey pair. The AccessKey secret is required only if the signature authentication mode is used.

Network parameters

Parameter

Description

networkRecoveryInterval

The amount of time that is required for a TCP connection to be automatically recovered. Unit: milliseconds. Default value: 5000.

connectionTimeout

The timeout period of a request that is sent to establish a TCP connection. Unit: milliseconds. Default value: 60000.

If a TCP connection fails to be established within the specified timeout period, an error response is returned.

handshakeTimeout

The timeout period for a TCP handshake. Unit: milliseconds. Default value: 10000.

If a TCP handshake fails to be performed within the specified timeout period, an error response is returned.

requestedHeartbeat

The heartbeat interval. Units: seconds. Default value: 60.

If no heartbeat information is sent within the specified interval, an error response is returned.

shutdownTimeout

The period during which a consumer can still process messages after a TCP connection is closed. Unit: milliseconds. Default value: 10000. If the parameter is set to 0, a consumer can process messages for an indefinite period of time after the TCP connection is closed.

Send messages

  • Interface name: sendMessage

  • Class name: com.alibaba.mqtt.server.ServerProducer

Table 1. Parameters

Parameter

Description

mqttTopic

The ApsaraMQ for MQTT topic to which messages are sent. You can specify a parent topic or a subtopic. If you specify a subtopic, messages are sent to the subtopic.

You must create parent topics in the ApsaraMQ for MQTT console. You can specify subtopics in the code without the need to create them in the console. For more information, see Basic terms.

Important

If you specify a topic that does not exist or on which you are not granted permissions, the Message Queue for MQTT client fails to be authenticated. As a result, the client is disconnected from the ApsaraMQ for MQTT broker.

payload

The body of the message.

sendCallback

The callback that is invoked when a message is sent. The message status is processed in the callback.

Subscribe to messages

  • Interface name: subscribeTopic

  • Class name: com.alibaba.mqtt.server.ServerConsumer

Table 2. Parameters

Parameter

Description

firstTopic

The parent topic that you created in the ApsaraMQ for MQTT console. For more information, see Basic terms.

Important
  • If you specify a topic that does not exist or on which you are not granted permissions, the Message Queue for MQTT client fails to be authenticated. As a result, the client is disconnected from the ApsaraMQ for MQTT broker.

  • In most cases, you use the cloud SDK to subscribe to messages in scenarios in which cloud applications collect and analyze messages. As a result, you cannot specify subtopics when you use the cloud SDK to subscribe to messages.

messageListener

The callback that is invoked when a message is subscribed to. The message is processed in the callback.

Subscribe to client status notifications

  • Interface name: subscribeStatus

  • Class name: com.alibaba.mqtt.server.ServerConsumer

Table 3. Parameters

Parameter

Description

mqttGroupId

The ID of the group that you created in the ApsaraMQ for MQTT console. For more information, see Basic terms.

statusListener

The callback that is invoked when a client status notification is subscribed to. The client status notification is processed in the callback.