This topic describes the parameters that are used in ApsaraMQ for MQTT cloud SDK for Go.

Common parameters

ParameterDescription
domainThe 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 the cloud SDK to connect to ApsaraMQ for MQTT, specify the endpoint in the following format:

Important You can use a cloud SDK to connect to only ApsaraMQ for MQTT instances whose kernel version is V3.3.0 and that are deployed in regions in the Chinese mainland.
  • 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.

portThe port that is used by the cloud SDK for Go. The protocol and port that are used by the cloud SDK must match. Set the value to 5672.
instanceIdThe 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.
accessKeyThe 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.
secretKeyThe 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.

Send messages

Table 1. Parameters
ParameterDescription
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 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.

Subscribe to messages

Table 2. Parameters
ParameterDescription
firstTopicThe parent topic that you created in the ApsaraMQ for MQTT console. For more information, see 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.

Subscribe to client status notifications

Table 3. Parameters
ParameterDescription
gid

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