This topic describes the demo projects for ApsaraMQ for MQTT and provides usage notes for using Message Queue for MQTT in various scenarios. For more information, see the comments of the source code of the demos.

Obtain demos for multiple programming languages

For the complete set of sample code, see mqtt-demo.

Decompress the downloaded package. The mqtt-demo-main folder is added. Level-1 folders are classified based on programming languages. Perform debugging based on your business requirements.

Java

ScenarioDownload link
Example on how to use only Message Queue for MQTT to send and subscribe to messagesmqtt.demo.java
Example on how to use the signature authentication mode of Message Queue for MQTTmqtt.signature.mode.demo.java
Example on how to use the token-based authentication mode of Message Queue for MQTTmqtt.token.mode.demo.java
Example on how to use the SSL encryption of Message Queue for MQTTmqtt.ssl.demo.java
Example on how to use Message Queue for MQTT to send messages and use Message Queue for Apache RocketMQ to subscribe to messagesmqtt.to.rocketmq.demo.java
Example on how to use Message Queue for Apache RocketMQ to send messages and use Message Queue for MQTT to subscribe to messagesrocketmq.to.mqtt.demo.java
Example on how to use Message Queue for MQTT to send ordered messages and use Message Queue for Apache RocketMQ to subscribe to ordered messagesmqtt.ordered.msg.demo.java
Example on how to configure asynchronous status notifications for Message Queue for MQTT clientsmqtt.client.status.notice.demo.java

Python

ScenarioDownload link
Example on how to use only Message Queue for MQTT to send and subscribe to messagesmqtt.demo.python
Example on how to use the signature authentication mode of Message Queue for MQTTmqtt.signature.mode.demo.python
Example on how to use the SSL encryption of Message Queue for MQTTmqtt.ssl.mode.demo.python

PHP

ScenarioDownload link
Example on how to use only Message Queue for MQTT to send and subscribe to messagesmqtt.demo.php
Example on how to use the signature authentication mode of Message Queue for MQTTmqtt.signature.mode.demo.php
Example on how to use the token-based authentication mode of Message Queue for MQTTmqtt.token.mode.demo.php
Example on how to use Message Queue for MQTT to send ordered messages and use Message Queue for Apache RocketMQ to subscribe to ordered messagesmqtt.ordered.msg.demo.php

C

ScenarioDownload link
Example on how to use only Message Queue for MQTT to send and subscribe to messagesmqtt.demo.c
Example on how to use the signature authentication mode of Message Queue for MQTTmqtt.signature.mode.demo.c
Example on how to use the SSL encryption of Message Queue for MQTTmqtt.ssl.demo.c
Note For more information about the dependency libraries for C, see eclipse/paho.mqtt.c.

.NET

ScenarioDownload link
Example on how to use only Message Queue for MQTT to send and subscribe to messagesmqtt.demo.net
Example on how to use the signature authentication mode of Message Queue for MQTTmqtt.signature.mode.demo.net
Example on how to use the SSL encryption of Message Queue for MQTTmqtt.ssl.mode.demo.net

JavaScript

ScenarioDownload link
Example on how to use only Message Queue for MQTT to send and subscribe to messagesmqtt.demo.javascript
Example on how to use the signature authentication mode of Message Queue for MQTTmqtt.signature.mode.demo.javascript
Example on how to use the SSL encryption of Message Queue for MQTTmqtt.ssl.demo.javascript
Example on how to use WebSocket to send and subscribe to messagesmqtt.websocket.demo.javascript

iOS

ScenarioDownload link
Example on how to use only Message Queue for MQTT to send and subscribe to messagesmqtt.demo.ios
Example on how to use the signature authentication mode of Message Queue for MQTTmqtt.signature.mode.demo.ios
Example on how to use the SSL encryption of Message Queue for MQTTmqtt.ssl.demo.ios

Usage notes

If you use ApsaraMQ for MQTT together with other backend message storage services such as ApsaraMQ for RocketMQ, make sure that you understand the mappings between message structures and attributes. For more information, see Message structure mappings between MQTT and RocketMQ.

Note The integrity of a demo varies based on the programming language. Updates for demos will be provided in future versions. If no demo is available for a feature, download the SDK for the corresponding programming language to test the feature. For more information, see Java examples.

Additional information

The sample code is provided only for reference. For information about how to obtain the SDK for a specific programming language, see Download the SDK.