This topic introduces the demo projects for ApsaraMQ for MQTT. These projects provide guidance for various scenarios. For more information, see the comments in the source code.
Get multi-language demos
For the complete sample code, see mqtt-demo.
After you download and decompress the package, a folder named mqtt-demo-main is created on your local machine. The top-level folders are categorized by programming language. You can debug the code as needed.
Java
Scenario | Download link |
Standalone MQTT message sending and receiving example | |
MQTT token example | |
MQTT SSL encryption example | |
Example of sending messages from MQTT and subscribing to them in ApsaraMQ for RocketMQ | |
Example of sending messages from ApsaraMQ for RocketMQ and subscribing to them in MQTT | |
Example of sending ordered messages from MQTT and subscribing to them as ordered messages in ApsaraMQ for RocketMQ | |
Example of asynchronous notifications for MQTT client online and offline status | |
MQTT SSL mutual authentication example |
Python
Scenario | Download link |
Standalone MQTT message sending and receiving example | |
MQTT SSL encryption example |
PHP
Scenario | Download link |
Standalone MQTT message sending and receiving example | |
MQTT token example | |
Example of sending ordered messages from MQTT and subscribing to them as ordered messages in ApsaraMQ for RocketMQ |
C
Scenario | Download link |
Standalone MQTT message sending and receiving example | |
MQTT SSL encryption example |
For more C dependency libraries, see eclipse/paho.mqtt.c.
.NET
Scenario | Download link |
Standalone MQTT message sending and receiving example | |
MQTT SSL encryption example |
JavaScript
Scenario | Download link |
Standalone MQTT message sending and receiving example | |
MQTT SSL encryption example | |
WebSocket message sending and receiving example |
iOS
Scenario | Download link |
Standalone MQTT message sending and receiving example | |
MQTT SSL encryption example |
Notes on using the demos
If you use ApsaraMQ for MQTT with other backend log brokers, such as ApsaraMQ for RocketMQ, you must understand the message structure and property mapping. For more information, see Message structure mapping between MQTT and ApsaraMQ for RocketMQ.
The demo programs for different programming languages may vary in completeness and are periodically updated. If a demo for a specific feature is not available, you can refer to the Java example, download the SDK for your language, and test the feature.
More information
The sample code is provided for reference only. To download an SDK for a specific language, see SDK downloads.