EMQX Documentation

repository·release-6.2·Indexed 41 days ago

https://github.com/emqx/emqx-docs

Official documentation for the EMQX MQTT broker, supporting both Open Source and Enterprise editions. Includes guides on HOCON configuration, REST API usage, CLI commands, and advanced features like Cluster Linking for connecting separate clusters across geographic regions.

Tokens
267.5K
Snippets
563
Records
957
Agent score
51%

What's inside EMQX

  1. Overview of EMQX

    release-6.2

    EMQX is a fully open-source, highly scalable, and highly available distributed MQTT message server. It is designed for IoT, M2M, and mobile applications, capable of handling tens of millions of concurrent clients.

    For more information, visit the EMQ official website. The source files for the Chinese documentation can be found in this repository.

  2. Overview of MQTT File Transfer in EMQX

    release-6.2

    EMQX provides file transfer capabilities built directly on top of the standard MQTT protocol. Instead of using hybrid approaches (like combining MQTT for signaling and HTTP/FTP for content), EMQX implements a simple application-level protocol on top of MQTT. This allows devices to transfer diverse data types—such as audio/video, images, and diagnostic logs—using their existing MQTT connections and security frameworks.

    Key capabilities include:

    • Unified Channel: Uses the same MQTT connection as regular business operations, leveraging existing device authentication and authorization.
    • Chunked Transfers: Enables lightweight clients to transfer large files, supporting files up to and exceeding the standard MQTT size limit (up to 256MB and beyond via chunking).
    • Resumable Transfers: Supports pausing transfers to prioritize other data or recovering from network interruptions.
    • Reliability: Uses QoS 1 level transmission combined with checksums and retransmission mechanisms to ensure 100% file integrity.
    • Flexible Storage: Files can be saved to a local directory or S3-compatible object storage.
  3. Overview of EMQX User Guides

    release-6.2

    The EMQX user guides provide instructions for administrators and operators to manage, configure, secure, monitor, and maintain EMQX deployments. Key operational areas include:

    • Cluster Management: Creating and managing clusters, including architecture, security, load balancing, node evacuation, and performance tuning.
    • Configuration: Managing the configuration file and detailed configuration options.
    • Multi-tenancy (Namespace): Logically grouping MQTT clients and managing tenant-level isolation, quotas, and rate limits.
    • Management Interfaces: Using the REST API for HTTP-based management of clients, topics, and subscriptions; the Command Line Interface (CLI) for startup and management; and the EMQX Dashboard for a visual management console.
    • Security: Configuring network/TLS settings, authentication, authorization, identity governance, and audit logs.
    • Data Durability: Configuring MQTT Durable Sessions and data replicas for high availability.
    • Observability: Monitoring metrics and system logs for debugging and system health.
    • Extensibility: Extending EMQX using Hooks (including gRPC hooks) and developing/managing Plugins.
  4. Stream MQTT Data into Apache Kafka

    release-6.2

    EMQX integrates with Apache Kafka (or Confluent) to bridge the gap between lightweight MQTT IoT devices and high-throughput backend streaming platforms. This integration allows for seamless data streaming where MQTT messages are ingested into Kafka topics for real-time processing, storage, and analysis, and data from Kafka topics can be delivered back to MQTT clients to trigger actions.

    Key capabilities include:

    • Bidirectional Messaging: Reliable transfer of messages from MQTT to Kafka (Sink) and Kafka to MQTT (Source).
    • Payload Transformation: Use EMQX SQL rules to filter, enhance, or transform payloads before they reach Kafka.
    • Flexible Topic Mapping: Map MQTT topics/user properties to Kafka topics/headers using 1:1, 1:N, or wildcard-based mapping.
    • Partitioning Strategies: Route messages to specific Kafka partitions based on MQTT topics or client IDs.
    • High Throughput: Support for both synchronous and asynchronous Kafka writes to balance latency and throughput.
    • Observability: Access runtime metrics such as total message counts, success/failure rates, and current rates for each Sink and Source.
  5. Ingest MQTT Data into Snowflake

    release-6.2

    EMQX provides a ready-to-use integration with Snowflake to facilitate IoT data warehousing and analytics. EMQX acts as the connectivity layer, while Snowflake serves as the storage and processing platform. This integration is achieved using the EMQX Rule Engine and a Snowflake Sink.

    Workflow Overview

    1. Device Connection: Devices connect to EMQX via MQTT, triggering online events.
    2. Message Publishing: Devices publish telemetry and status data to specific topics.
    3. Rule Engine Processing: EMQX rules match topics and perform data transformation, filtering, or enrichment.
    4. Writing to Snowflake: The rule triggers a Sink to write data using one of two modes:
      • Aggregated Mode: Batches messages into files and loads them via Snowflake Stage and Pipe.
      • Streaming Mode: Streams data directly using the Snowpipe Streaming API.

    Use Cases

    • Data Archiving: Long-term, compliant storage of IoT data.
    • Data Analytics: Real-time or batch analysis for predictive maintenance and operational insights.
  6. Use the EMQX Mapping Tables plugin for Rule SQL

    release-6.2

    The EMQX Mapping Tables plugin (available from EMQX 6.1.5+) allows you to map stable identifiers, codes, or binary field IDs to structured values within Rule SQL. Instead of using long CASE WHEN expressions, you can use the maptab_lookup SQL function to query named mapping tables.

    To use this feature, you must install and start the plugin before calling maptab_lookup in your rules.

    -- Example usage in Rule SQL
    maptab_lookup('table_name', lookup_key)
  7. Use the EMQX Mapping Tables plugin

    release-6.2

    The EMQX Mapping Tables plugin (available from EMQX 6.2.3+) allows you to use named mapping tables within Rule SQL. This is useful for mapping stable identifiers, codes, or binary field IDs to structured values using the maptab_lookup function, avoiding long CASE WHEN expressions in your SQL statements.

    To use this feature, you must install and start the plugin before attempting to call maptab_lookup in a rule.

    -- Example usage in Rule SQL
    maptab_lookup('table_name', lookup_key)
  8. Benefits of using EMQX Webhook for data integration

    release-6.2

    Using Webhooks for integration offers several advantages:

    • Broad Downstream Compatibility: Easily connect MQTT data to a wide variety of external systems like analytics platforms or cloud services.
    • Real-time Response: External systems receive MQTT data in real-time, allowing them to trigger business processes immediately (e.g., starting a workflow upon receiving alarm data).
    • Customizable Data Processing: Since data is sent to an external HTTP server, you can implement complex business logic and data transformations without being limited by EMQX's built-in features.
    • Loosely Coupled Architecture: Uses a simple HTTP interface, providing a decoupled method for system integration.
  9. Use the MQTT Bridge with Disk Queue plugin

    release-6.2

    The emqx_bridge_mqtt_dq plugin forwards local MQTT messages to a remote MQTT broker using a disk-based buffer for resilience. It provides automatic retries when the remote broker is unavailable and supports topic rewriting.

    Key Features

    • Disk Buffering: Per-bridge disk queue partitions to prevent data loss during network outages.
    • Automatic Retries: Continues attempting to publish if the remote broker is unreachable.
    • Topic Rewriting: Use ${topic} in remote_topic to transform the destination topic.
    • Resilience: If a queue partition exceeds queue.max_total_bytes, the oldest records in that partition are dropped to protect disk space.

    How It Works

    1. Local publishes are matched against a bridge's filter_topic.
    2. Matching messages are appended to disk queue partitions.
    3. Messages are published to the remote broker.
    4. If publishing fails due to connectivity, the plugin retries automatically.
    bridges {
      to-cloud {
        enable = true
        remote = cloud
        filter_topic = "devices/#"
        remote_topic = "fwd/${topic}"
        queue {
          max_total_bytes = "1GB"
        }
      }
    }
    
    remotes {
      cloud {
        server = "cloud-broker.example.com:8883"
        username = "bridge_user"
        password = "secret"
      }
    }
  10. Benefits of using Snowflake Sink for IoT data

    release-6.2

    Using the Snowflake Sink in EMQX provides several advantages for IoT workloads:

    • Message Transformation: Transform and process messages via the EMQX Rule Engine before they reach Snowflake.
    • Flexible Data Operations: Selectively write specific fields to Snowflake for efficient, dynamic storage configuration.
    • Integrated Business Processes: Connect device data directly to Snowflake's ecosystem for advanced analytics and archiving.
    • Low-Cost Long-Term Storage: Leverage Snowflake's scalable infrastructure for cost-effective long-term data retention compared to traditional databases.
  11. Typical Use Cases for MQTT Streams

    release-6.2

    MQTT Streams can be used for several architectural patterns:

    • Historical Data Replay: Reprocess past MQTT events for debugging or new business logic.
    • Time-Series Analysis: Store and replay sensor data for analytics and predictive maintenance.
    • Event Sourcing: Persist all state changes as an immutable event log.
    • IoT Digital Twins: Maintain the latest state of physical devices in digital form.
    • Configuration Synchronization: Ensure devices always receive the most recent configuration.
  12. Features and benefits of HStreamDB integration

    release-6.2

    Integrating EMQX with HStreamDB provides several capabilities:

    • Reliable Delivery: Batching and sending MQTT messages to HStreamDB.
    • Message Transformation: Using the EMQX rule engine to extract, filter, enrich, and transform data before it reaches the database.
    • Scalable Storage: Leveraging HStreamDB's distributed, fault-tolerant log storage for millions of data streams.
    • Cloud-Native Scalability: Both EMQX and HStreamDB support horizontal scaling and dynamic cluster expansion.
    • SQL-Based Processing: Use standard SQL within HStreamDB to filter, transform, aggregate, and join data streams via materialized views.
    • High-Throughput Modes: Supports both synchronous and asynchronous write modes to balance latency and throughput requirements.