# EMQX

> Scalable MQTT broker for IoT.

- Category: Message Queues & Brokers
- Difficulty: intermediate
- Components: emqx
- Tags: emqx, mqtt, iot, scalable
- Source: https://docker.recipes/messaging/emqx

## Overview

EMQX is a high-performance, open-source MQTT broker designed specifically for IoT and real-time messaging applications. Originally developed by EMQ Technologies, EMQX has evolved into one of the most scalable MQTT brokers available, capable of handling millions of concurrent connections while maintaining low latency and high throughput. Built on Erlang/OTP, it leverages the actor model for exceptional fault tolerance and distributed computing capabilities. This Docker deployment provides a complete EMQX broker instance with multiple protocol endpoints and a comprehensive web dashboard for monitoring and management. The configuration exposes standard MQTT ports (1883), secure MQTT over SSL (8883), WebSocket connections (8083/8084), and the administrative dashboard (18083), making it suitable for both development and production IoT environments. EMQX excels in scenarios requiring massive device connectivity, real-time data streaming, and complex message routing rules. The broker's built-in rule engine allows for real-time data processing and transformation without requiring external components. This makes EMQX particularly valuable for IoT platform developers, industrial automation companies, and organizations building large-scale device management systems where message reliability and horizontal scalability are critical requirements.

## Features

- Massive concurrent connection support with millions of MQTT clients per node
- Built-in rule engine for real-time message processing, filtering, and transformation
- Multiple protocol support including MQTT 3.1.1, MQTT 5.0, WebSocket, and CoAP
- Hot configuration updates without service interruption or connection drops
- Advanced authentication and authorization with JWT, OAuth 2.0, and custom plugins
- Message persistence and replay capabilities for reliable delivery guarantees
- Comprehensive monitoring and alerting through built-in metrics and webhook notifications
- Plugin architecture supporting custom extensions for databases, message queues, and cloud services

## Use cases

- IoT device management platforms requiring high-volume sensor data collection
- Industrial automation systems with real-time machine-to-machine communication
- Smart city infrastructure connecting traffic lights, environmental sensors, and public displays
- Vehicle telematics platforms tracking fleet location, diagnostics, and driver behavior
- Home automation hubs managing smart thermostats, security cameras, and lighting systems
- Real-time chat applications and mobile push notification services
- Financial trading platforms requiring low-latency market data distribution

## Prerequisites

- Minimum 2GB RAM for basic deployment, 4GB+ recommended for production workloads
- Available ports 1883, 8083, 8084, 8883, and 18083 on the host system
- Basic understanding of MQTT protocol concepts and publish/subscribe messaging patterns
- Familiarity with SSL certificate management for secure MQTT connections
- Network configuration knowledge for firewall rules and load balancer setup
- Understanding of IoT device authentication methods and connection security

## docker-compose.yml

```yaml
services:
  emqx:
    image: emqx/emqx:latest
    container_name: emqx
    restart: unless-stopped
    environment:
      EMQX_NAME: emqx
      EMQX_HOST: 127.0.0.1
    volumes:
      - emqx_data:/opt/emqx/data
      - emqx_log:/opt/emqx/log
    ports:
      - "1883:1883"
      - "8083:8083"
      - "8084:8084"
      - "8883:8883"
      - "18083:18083"

volumes:
  emqx_data:
  emqx_log:
```

## .env

```bash
# Default dashboard: admin / public
```

## Usage notes

- Docs: https://www.emqx.io/docs/
- Dashboard at http://localhost:18083, default: admin/public
- MQTT on 1883, MQTT/SSL on 8883, WebSocket on 8083/8084
- Supports millions of concurrent connections
- Built-in rule engine for data processing
- Enterprise features: clustering, bridges, integrations

## Troubleshooting

- Connection refused on port 1883: Verify the container is running and port mapping is correct with 'docker ps'
- Dashboard shows 'admin/public' login failure: Reset credentials using 'docker exec emqx emqx_ctl admins passwd admin newpassword'
- High memory usage with many connections: Increase Docker memory limits and tune EMQX connection pool settings
- SSL/TLS handshake failures on port 8883: Check certificate validity and ensure proper SSL configuration in EMQX settings
- Message delivery delays under load: Adjust EMQX message queue limits and enable message persistence for better throughput
- WebSocket connection timeouts: Configure proxy timeout settings and check for network connectivity issues between clients and port 8083/8084

