A complete real-time messaging starter project featuring a Harper application with MQTT, WebSocket, and Server-Sent Events (SSE) capabilities, plus client examples in multiple languages.
This repository provides everything you need to get started with real-time messaging using Harper:
- Harper Application - A Harper application with built-in MQTT broker and real-time capabilities
- Client Examples - Publisher and subscriber implementations using MQTT, WebSocket, and SSE in Node.js, Python, and MQTTX CLI
This project uses pyenv for Python environment management. Run the setup script to configure everything:
./setup.shOr manually:
# Create and activate Python environment
pyenv virtualenv 3.11 mqtt-getting-started
pyenv local mqtt-getting-started
# Install dependencies
pip install -r requirements.txt
cd harper && npm install
cd client/nodejs && npm installSet up and run the Harper application:
cd harper
npm install
npm run devSee the harper/README.md for detailed setup and configuration.
Once the Harper application is running, choose your preferred client implementation:
# Node.js
cd client/nodejs && npm install
# Python (environment already activated via .python-version)
cd client/python
# MQTTX CLI
cd client/mqttx && ./install.shEach client directory contains its own README with specific instructions.
harper-mqtt-getting-started/
├── harper/ # Harper application with real-time capabilities
│ ├── config.yaml # Application configuration
│ ├── schema.graphql # Database schema
│ ├── resources.js # Application logic
│ └── package.json
└── client/ # Real-time client examples
├── nodejs/ # Node.js clients (MQTT, WebSocket, SSE)
│ ├── mqtt-publish.js
│ ├── mqtt-subscribe.js
│ ├── ws-publish.js
│ ├── ws-subscribe.js
│ ├── sse-subscribe.js
│ └── package.json
├── python/ # Python clients (MQTT, WebSocket, SSE)
│ ├── mqtt-publish.py
│ ├── mqtt-subscribe.py
│ ├── ws-publish.py
│ ├── ws-subscribe.py
│ ├── sse-subscribe.py
│ └── requirements.txt
└── mqttx/ # MQTTX CLI shell scripts
├── mqttx_publish.sh
├── mqttx_subscribe.sh
└── install.sh
Real-time clients supporting MQTT, WebSocket, and SSE.
- MQTT: Full pub/sub broker with topic-based routing using
mqttpackage - WebSocket: Bidirectional communication using
wspackage - SSE: Server-to-client streaming using
eventsourcepackage - Supports modern async/await patterns
- Easy to integrate into existing Node.js projects
Real-time clients supporting MQTT, WebSocket, and SSE.
- MQTT: Industry-standard
paho-mqttlibrary - WebSocket: Async support with
websocketslibrary - SSE: Server-to-client streaming using
sseclient-pylibrary - Clean and readable Python code
- Great for IoT and data processing applications
Shell script examples using the MQTTX command-line tool.
- No programming required
- Quick testing and debugging
- Platform-agnostic command-line interface
- MQTT: Full pub/sub broker, topic-based routing, QoS levels, requires retain flag for persistence
- WebSocket: Bidirectional communication, direct resource connection, automatic persistence, lower overhead
- SSE: Unidirectional (server→client), simple HTTP-based, automatic reconnection, automatic persistence
All publishers support two modes of operation:
Run without arguments to continuously publish auto-generated messages every 5 seconds:
# Node.js
node client/nodejs/mqtt-publish.js
node client/nodejs/ws-publish.js
# Python
python3 client/python/mqtt-publish.py
python3 client/python/ws-publish.py
# MQTTX CLI
client/mqttx/mqttx-publish.shProvide a JSON payload as an argument for testing (used by test suite):
# Node.js
node client/nodejs/mqtt-publish.js '{"temp":72.5,"location":"test-lab"}'
# Python
python3 client/python/mqtt-publish.py '{"temp":72.5,"location":"test-lab"}'
# MQTTX CLI
client/mqttx/mqttx-publish.sh '{"temp":72.5,"location":"test-lab"}'MQTT messages support persistence control via the MQTT_RETAIN environment variable:
MQTT_RETAIN=true(default): Messages are retained and stored in the databaseMQTT_RETAIN=false: Messages are ephemeral, forwarded to active subscribers only, not stored
# Persistent message (stored in database)
node client/nodejs/mqtt-publish.js '{"temp":72.5,"location":"warehouse"}'
# Ephemeral message (not stored, only forwarded to active subscribers)
MQTT_RETAIN=false node client/nodejs/mqtt-publish.js '{"temp":72.5,"location":"warehouse"}'
# Also works in continuous mode
MQTT_RETAIN=false python3 client/python/mqtt-publish.pyNote: WebSocket messages to Harper resources are always persisted automatically.
Automated tests verify that messages published via any protocol (MQTT/WebSocket) are received by all subscribers across all protocols and languages.
Last run: 2025-12-23 21:51:26 UTC
| Publisher (rows) / Subscriber (columns) | nodejs-mqtt | nodejs-ws | nodejs-sse | python-mqtt | python-ws | python-sse | mqttx-mqtt |
|---|---|---|---|---|---|---|---|
| Node.js MQTT | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Node.js WS | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Python MQTT | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Python WS | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| MQTTX MQTT | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Run all tests with one command:
cd client
./test.shThis will:
- Launch all 7 subscribers in background
- Test each of the 5 publishers sequentially
- Verify all subscribers receive each message
- Display a summary report
You can also run components separately:
Start subscribers:
./run-all-subscribers.shView subscriber logs:
tail -f ../test-logs/*.logRun publisher tests:
./run-publishers.shStop subscribers:
./run-all-subscribers.sh stop- 7 Subscribers: nodejs-mqtt, nodejs-ws, nodejs-sse, python-mqtt, python-ws, python-sse, mqttx-mqtt
- 5 Publishers: nodejs-mqtt, nodejs-ws, python-mqtt, python-ws, mqttx-mqtt
- Cross-protocol verification: Each publisher's message must reach all 7 subscribers
- Log-based monitoring: Subscribers write to log files in
test-logs/ - Automated verification: Test script parses subscriber logs and reports pass/fail
- Harper running on localhost:9926
- MQTT broker running on localhost:1883
- mqttx-cli (install:
npm install -g @emqx/mqttx-cliorbrew install emqx/mqttx/mqttx-cli)
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.