jmqtt Documentation

repository·master·Indexed 19 days ago

https://github.com/cicizz/jmqtt

A high-performance MQTT broker supporting the 3.1.1 protocol with MySQL-based clustering and data persistence. It supports TCP, WebSocket, SSL, and WSS transport protocols and is designed for extensibility via plugins for storage, connection, and authentication logic. Key features include support for QoS 0, 1, and 2, retain and will messages, and offline messaging.

Tokens
2.9K
Snippets
9
Records
21
Agent score
63%

What's inside jmqtt

  1. Overview of Jmqtt features

    master

    Jmqtt is an MQTT broker that provides full support for the MQTT 3.1.1 protocol. Key capabilities include:

    • Protocol Support: Full MQTT 3.1.1 compliance.
    • Persistence & Clustering: Data persistence and clustering capabilities powered by MySQL.
    • Extensibility: Designed for secondary development and plugin development, specifically for cluster management, storage, device connections, and publish/subscribe authentication.
    • Transport Protocols: Supports TCP, WebSocket, SSL, and WSS.
  2. Supported MQTT Features in Jmqtt

    master

    Jmqtt supports a wide range of standard MQTT features, including cluster connectivity, various Quality of Service (QoS) levels, and message persistence.

    Supported Features:

    • Cluster Connectivity: Supports cluster connections and message forwarding between devices in a cluster.
    • Session Management: Supports cleansession=false connections.
    • Message Types: Supports Retain messages and Will messages.
    • QoS Levels: Supports qos0, qos1, and qos2.
    • Offline Messaging: Supports offline messages with no limit on the number of messages.
    • Persistence:
      • Device information is persisted in the jmqtt_session SQL table.
      • Subscription relationships are persisted in the jmqtt_subscription SQL table.
      • Messages are persisted in the jmqtt_message SQL table.
      • Cluster events (inter-cluster forwarding, connection events) are persisted in the jmqtt_cluser_event SQL table.
      • Device message reception status is tracked in the jmqtt_client_inbox SQL table.

    Unsupported Features (Requires manual implementation):

    • Monitoring topics
    • Message bridging
    • Rule engine
  3. Optimize Jmqtt performance and throughput

    master

    If you encounter performance bottlenecks, consider the following optimizations:

    • Database Throughput: Message sending performance is heavily dependent on the database (MySQL) for persistence. Upgrading MySQL or switching to a more performant storage middleware like a Time Series Database (TSDB) or Kafka can improve TPS.
    • Cluster Event Forwarding: Instead of having cluster nodes perform long-polling on the database, replace the current mechanism with a Message Queue (e.g., Kafka) to handle event forwarding more efficiently.
  4. Jmqtt Performance Benchmarks

    master

    Based on internal testing, Jmqtt demonstrates high scalability for both single-node and cluster configurations.

    Single-Node Performance

    • Connection Capacity: Achieved 100,000+ concurrent connections with a connection TPS of 1,000 without errors.
    • Message Throughput: Tested with 20,000 existing long-lived connections while simultaneously sending messages (e.g., 256-byte messages at QoS 0 or QoS 1).
    • Subscription Performance: Capable of handling 20,000 devices subscribing to 20,000 unique topics.

    Cluster Performance

    • Scalability: In a two-node cluster configuration, the system successfully handled 100,000 concurrent device connections without reaching the tested limit.

    Note: These benchmarks are provided for reference only. Users should perform their own testing based on their specific hardware and production requirements.

  5. Build Jmqtt from source

    master

    To build the project, navigate to the broker module and use Maven with the package-all profile. It is recommended to build from the source code or the latest master branch for the best results. Skipping tests during the build process is supported via the -DskipTests flag.

    cd broker
    mvn -Ppackage-all -DskipTests clean install -U
  6. Quick start: Build and run Jmqtt

    master

    To build and run Jmqtt from source, follow these steps:

    1. Download or Clone: Download a release (version 3.x or higher) from the releases page or clone the repository.
    2. Build the Broker: Navigate to the broker module and execute the Maven command to package all dependencies and install the project.
    3. Configure: Set up the configuration files and initialize the database using the SQL scripts found in the /jmqtt-broker/resources/conf directory.
    4. Run: Execute the broker JAR file, specifying the configuration directory using the -h flag. The directory must contain jmqtt.properties, log4j2.xml, and other necessary configuration files.
    # 1. Build the broker module
    cd broker
    mvn -Ppackage-all -DskipTests clean install -U
    
    # 2. Run the broker (replace ${conf_dir} with your actual config directory path)
    java -jar jmqtt-broker-3.0.0.jar -h ${conf_dir}
  7. Initialize the database for Jmqtt

    master

    Jmqtt uses MySQL by default. Before starting the broker, you must initialize your database by executing the provided SQL script. This ensures the necessary schema and tables are present for message and subscription storage.

    -- Execute this script in your MySQL database
    jmqtt.sql
  8. Set up the jmqtt documentation site

    master

    To build and run the official documentation site locally, follow these steps:

    1. Clone the repository.
    2. Ensure npm or yarn is installed (refer to the VuePress getting started guide if needed).
    3. Install vuepress as a development dependency.
    4. Start the local development server.
    5. Build the static site.

    Note: This process is intended for developers who want to contribute to or host the documentation site itself using VuePress.

    # 1. Clone the repository
    # (Use your preferred git client)
    
    # 2. Install vuepress
    yarn add -D vuepress
    
    # 3. Start local development
    yarn dev
    
    # 4. Build the site
    yarn build