EMQX Consumer

A Node.js MQTT consumer application that connects to EMQX broker.

Features

  • MQTT message consumption
  • Configurable connection settings
  • Error handling and reconnection
  • Clean architecture
  • Test coverage

Prerequisites

  • Node.js >= 16.x
  • npm >= 8.x

Installation

  1. Clone the repository
git clone <repository-url>
cd emqx-consumer
  1. Install dependencies
npm install
  1. Configure environment variables
cp .env.example .env
# Edit .env with your configuration

Usage

Development

npm run dev

Production

npm start

Testing

npm test

Linting

npm run lint

Formatting

npm run format

Configuration

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 connection
  • MQTT_USERNAME: Username for MQTT authentication (optional)
  • MQTT_PASSWORD: Password for MQTT authentication (optional)

Project Structure

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

License

ISC