A Node.js MQTT consumer application that connects to EMQX broker.
- MQTT message consumption
- Configurable connection settings
- Error handling and reconnection
- Clean architecture
- Test coverage
- Node.js >= 16.x
- npm >= 8.x
- Clone the repository
git clone <repository-url>
cd emqx-consumer
- Install dependencies
npm install
- Configure environment variables
cp .env.example .env
# Edit .env with your configuration
npm run dev
npm start
npm test
npm run lint
npm run format
Configuration is handled through environment variables:
MQTT_BROKER_URL
: MQTT broker URL (default: mqtt://broker.emqx.io)MQTT_TOPIC
: Topic to subscribe to (default: jsstg_demo/messages)MQTT_CLIENT_ID
: Client ID for MQTT connectionMQTT_USERNAME
: Username for MQTT authentication (optional)MQTT_PASSWORD
: Password for MQTT authentication (optional)
emqx-consumer/
├── src/ # Source files
│ ├── config/ # Configuration files
│ │ └── mqtt.config.js # MQTT configuration
│ ├── services/ # Business logic
│ │ └── mqtt.service.js # MQTT service
│ └── index.js # Application entry point
├── tests/ # Test files
│ └── mqtt.service.test.js # MQTT service tests
└── [configuration files] # Various config files
ISC