This topic describes the interfaces that are provided by Message Queue 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 Message Queue for MQTT instance. A Message Queue for MQTT client uses an endpoint of a Message Queue for MQTT instance to connect to the Message Queue for MQTT broker.

To obtain the endpoints of a Message Queue for MQTT instance, .

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 Message Queue for MQTT console. You can view the instance ID on the Instance Details page of the Message Queue for MQTT console.
accessKey The AccessKey ID that you created in the Resource Access Management (RAM) console for identity verification. 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 verification. 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 Message Queue 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 Message Queue for MQTT console. You can define subtopics in the code without the need to create them in the console. For more information, see Terms.

Notice 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 Message Queue 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 Message Queue for MQTT console. For more information, see Terms.
Notice 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 Message Queue for MQTT broker.
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 Message Queue for MQTT console. For more information, see Terms.

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