ApsaraMQ for MQTT demo projects cover common scenarios with inline code comments for guidance.
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 |
Usage notes
If you use ApsaraMQ for MQTT with backend message brokers such as ApsaraMQ for RocketMQ, review the Mapping between MQTT and ApsaraMQ for RocketMQ message structures.
Demo coverage varies by language and is updated periodically. If a demo is unavailable for your language, refer to the Java example, download the SDK, and test.
More information
Sample code is for reference only. Download language-specific SDKs from SDK downloads.