Convert Figma logo to code with AI

moquette-io logomoquette

Java MQTT lightweight broker

2,377
826
2,377
117

Top Related Projects

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.

15,076

The most scalable and reliable MQTT broker for AI, IoT, IIoT and connected vehicles

HiveMQ CE is a Java-based open source MQTT broker that fully supports MQTT 3.x and MQTT 5. It is the foundation of the HiveMQ Enterprise Connectivity and Messaging Platform

The mqtt.org website

Eclipse Mosquitto - An open source MQTT broker

3,369

A distributed MQTT message broker based on Erlang/OTP. Built for high quality & Industrial use cases. The VerneMQ mission is active & the project maintained. Thank you for your support!

Quick Overview

Moquette is an open-source, lightweight MQTT broker written in Java. It is designed to be easy to embed in applications and provides a simple and efficient way to implement MQTT-based communication in Java projects.

Pros

  • Lightweight and Embeddable: Moquette is a small and lightweight MQTT broker that can be easily embedded into applications, making it suitable for use in resource-constrained environments.
  • Simple Configuration: Moquette has a straightforward configuration process, allowing developers to quickly set up and customize the broker to fit their needs.
  • Scalable Performance: Moquette is designed to handle a large number of concurrent connections and messages, making it suitable for use in high-traffic applications.
  • Flexible Authentication and Authorization: Moquette supports various authentication and authorization mechanisms, including username/password, client certificates, and custom plugins.

Cons

  • Limited Documentation: The project's documentation could be more comprehensive, which may make it challenging for new users to get started.
  • Lack of Enterprise-level Features: Compared to some commercial MQTT brokers, Moquette may lack certain advanced features required in enterprise-level applications.
  • Dependency on Java: As Moquette is written in Java, it may not be the best choice for projects that do not use Java as the primary language.
  • Potential Performance Limitations: While Moquette is designed to be scalable, it may not be able to match the performance of more specialized MQTT brokers in high-load scenarios.

Code Examples

Here are a few examples of how to use Moquette in your Java projects:

  1. Embedding the Moquette Broker:
MoquetteServerBootstrapper server = new MoquetteServerBootstrapper();
server.startServer();
  1. Configuring the Moquette Broker:
MoquetteServerBootstrapper server = new MoquetteServerBootstrapper();
server.startServer(new MoquetteSettings()
    .setPort(1883)
    .setWebsocketPort(8080)
    .setPassword("mypassword")
    .setAuthenticator(new MyCustomAuthenticator()));
  1. Handling MQTT Messages:
MoquetteServerBootstrapper server = new MoquetteServerBootstrapper();
server.startServer();
server.getServer().addMessageHandler((topic, message) -> {
    System.out.println("Received message on topic " + topic + ": " + new String(message));
});
  1. Connecting to the Moquette Broker:
MqttClient client = new MqttClient("tcp://localhost:1883", "my-client-id");
client.connect();
client.subscribe("my/topic");
client.publish("my/topic", "Hello, Moquette!".getBytes(), 0, false);

Getting Started

To get started with Moquette, follow these steps:

  1. Add the Moquette Dependency: Add the Moquette dependency to your project's build file. For example, in a Maven project, add the following to your pom.xml:
<dependency>
    <groupId>io.moquette</groupId>
    <artifactId>moquette-broker</artifactId>
    <version>0.14.1</version>
</dependency>
  1. Start the Moquette Broker: Create a new instance of the MoquetteServerBootstrapper and call the startServer() method to start the MQTT broker:
MoquetteServerBootstrapper server = new MoquetteServerBootstrapper();
server.startServer();
  1. Configure the Broker: Customize the broker's settings, such as the port, authentication, and authorization, by passing a MoquetteSettings object to the startServer() method:
MoquetteSettings settings = new MoquetteSettings()
    .setPort(1883)
    .setWebsocketPort(8080)
    .setPassword("mypassword")
    .setAuthenticator(new MyCustomAuthenticator

Competitor Comparisons

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.

Pros of paho.mqtt.java

  • More comprehensive MQTT client library with support for various MQTT versions
  • Better documentation and wider community support
  • Actively maintained with regular updates and bug fixes

Cons of paho.mqtt.java

  • Larger codebase and potentially higher resource usage
  • Steeper learning curve for beginners due to more features
  • Lacks built-in broker functionality (client-only library)

Code Comparison

Moquette (Server setup):

final IConfig config = new MemoryConfig(new Properties());
final Server server = new Server();
server.startServer(config);

paho.mqtt.java (Client connection):

MqttClient client = new MqttClient("tcp://localhost:1883", "ClientId");
MqttConnectOptions options = new MqttConnectOptions();
client.connect(options);

While Moquette focuses on providing a lightweight MQTT broker, paho.mqtt.java is primarily a client library. Moquette's code snippet demonstrates server setup, whereas paho.mqtt.java shows client connection. paho.mqtt.java offers more flexibility for client-side MQTT operations, while Moquette is better suited for implementing a simple MQTT broker.

15,076

The most scalable and reliable MQTT broker for AI, IoT, IIoT and connected vehicles

Pros of emqx/emqx

  • Scalable and high-performance MQTT broker, capable of handling millions of concurrent connections
  • Supports a wide range of MQTT features, including WebSocket, TLS, and clustering
  • Extensive plugin system for customizing and extending the broker's functionality

Cons of emqx/emqx

  • Larger codebase and more complex to set up compared to Moquette
  • May have a steeper learning curve for users unfamiliar with MQTT brokers
  • Potential performance overhead for smaller-scale deployments

Code Comparison

Moquette (5 lines):

public class Server {
    public static void main(String[] args) {
        Server server = new Server();
        server.startServer();
    }
}

emqx (5 lines):

-module(emqx_app).

start(_Type, _Args) ->
    emqx_logger:init(),
    emqx_sup:start_link().

HiveMQ CE is a Java-based open source MQTT broker that fully supports MQTT 3.x and MQTT 5. It is the foundation of the HiveMQ Enterprise Connectivity and Messaging Platform

Pros of HiveMQ Community Edition

  • Robust and feature-rich MQTT broker with enterprise-grade capabilities
  • Extensive documentation and community support
  • Supports advanced MQTT features like retained messages, last will and testament, and more

Cons of HiveMQ Community Edition

  • Closed-source, with a commercial license required for production use
  • May have a steeper learning curve compared to Moquette
  • Potential vendor lock-in concerns for some users

Code Comparison

Moquette (MQTT Broker):

public class Server {
    public static void main(String[] args) {
        Server server = new Server();
        server.startServer();
    }

    private void startServer() {
        MoquetteServerBootstrapper bootstrapper = new MoquetteServerBootstrapper();
        bootstrapper.startServer();
    }
}

HiveMQ Community Edition (MQTT Broker):

public class HiveMQEntryPoint {
    public static void main(String[] args) {
        HiveMQEntryPoint entryPoint = new HiveMQEntryPoint();
        entryPoint.start();
    }

    private void start() {
        HiveMQServer hiveMQServer = new HiveMQServer();
        hiveMQServer.start();
    }
}

The mqtt.org website

Pros of MQTT.org

  • MQTT.org is the official website and repository for the MQTT protocol, providing authoritative information and resources.
  • The repository contains the MQTT protocol specification, which is the definitive reference for the protocol.
  • The website offers a comprehensive set of documentation, including tutorials, client libraries, and broker implementations.

Cons of MQTT.org

  • The repository is primarily focused on the protocol specification and documentation, rather than providing a specific implementation of the MQTT broker.
  • The repository does not contain any code for a broker implementation, which may be a limitation for users looking for a ready-to-use MQTT broker.

Code Comparison

Moquette-io/Moquette (MQTT Broker Implementation):

public class Server {
    private static final Logger LOG = LoggerFactory.getLogger(Server.class);

    private final MoquetteIdleTimeoutHandler idleHandler;
    private final MoquetteNettyInitializer initializer;
    private final MoquetteNettyBridge bridge;
    private final MoquetteNettyBootstrapper bootstrapper;

    public Server() {
        this.idleHandler = new MoquetteIdleTimeoutHandler();
        this.initializer = new MoquetteNettyInitializer(idleHandler);
        this.bridge = new MoquetteNettyBridge();
        this.bootstrapper = new MoquetteNettyBootstrapper(initializer, bridge);
    }

    // ...
}

MQTT.org (Protocol Specification):

3.1.2.1 CONNECT Packet
The CONNECT packet is the first packet sent from the Client to the Server. It is used by the Client to request a connection to the Server.

Fixed header
The fixed header format is:

Bit 7 6 5 4 3 2 1 0
byte 1 MQTT Control Packet type (1)
Bit 7 6 5 4 3 2 1 0
byte 2 Remaining Length

Eclipse Mosquitto - An open source MQTT broker

Pros of Mosquitto

  • Written in C, offering better performance and lower resource usage
  • Mature project with extensive documentation and community support
  • Supports a wider range of MQTT features and versions

Cons of Mosquitto

  • Less portable than Java-based alternatives
  • More complex to set up and configure for beginners
  • Requires compilation for different platforms

Code Comparison

Mosquitto (C):

int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, int payloadlen, const void *payload, int qos, bool retain);

Moquette (Java):

public void publish(String topic, byte[] message, QOSType qos, boolean retained) throws MqttException;

Both implementations provide similar functionality for publishing MQTT messages, but Mosquitto's C implementation offers more fine-grained control over message parameters.

Mosquitto is a robust, high-performance MQTT broker suitable for production environments and resource-constrained devices. Moquette, being Java-based, offers better portability and ease of use for Java developers, but may have higher resource requirements. The choice between the two depends on specific project needs, performance requirements, and development preferences.

3,369

A distributed MQTT message broker based on Erlang/OTP. Built for high quality & Industrial use cases. The VerneMQ mission is active & the project maintained. Thank you for your support!

Pros of VerneMQ

  • VerneMQ is a highly scalable and fault-tolerant MQTT broker, capable of handling a large number of concurrent connections and messages.
  • It supports a wide range of MQTT features, including QoS levels, retained messages, and WebSocket support.
  • VerneMQ has a modular design, allowing for easy customization and integration with other systems.

Cons of VerneMQ

  • VerneMQ may have a steeper learning curve compared to Moquette, especially for users new to MQTT brokers.
  • The documentation for VerneMQ, while comprehensive, may not be as user-friendly as Moquette's.
  • VerneMQ may have a higher resource footprint compared to Moquette, depending on the specific use case and deployment requirements.

Code Comparison

Here's a brief code comparison between Moquette and VerneMQ:

Moquette (Java):

public class MoquetteServer {
    public static void main(String[] args) {
        final Server server = new Server();
        server.startServer();
        Runtime.getRuntime().addShutdownHook(new Thread(() -> server.stopServer()));
    }
}

VerneMQ (Erlang):

-module(vmq_server_app).
-behaviour(application).

start(_Type, _Args) ->
    vmq_server_sup:start_link().

stop(_State) ->
    ok.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Java CI with Maven

Moquette MQTT broker

Documentation reference guide Guide on how to use and configure Moquette

Moquette is a lightweight broker compliant with MQTT 5 and MQTT 3, easily encapsulated in other applications. The broker supports QoS 0, QoS 1 and QoS 2. The MQTT5 specification is almost fully supported. The features implemented by the broker are:

  • session and message expiry
  • shared subscriptions
  • request/response
  • topic alias
  • flow control
  • subscription options
  • will delay
  • server disconnects
  • payload format indicator

Its designed to be evented, uses Netty for the protocol encoding and decoding part.

Community feedback

We would love :heart: to hear from Moquette users, please let us know how you use it 👣

Embedding in other projects

Use JitPack to resolve Moquette dependency in your project.

In repositories section, add:

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>

In dependencies section add:

<dependency>
  <groupId>com.github.moquette-io.moquette</groupId>
  <artifactId>moquette-broker</artifactId>
  <version>0.18.0</version>
</dependency>

Build from sources

After a git clone of the repository, cd into the cloned sources and: ./gradlew package, at the end the distribution package is present at distribution/target/distribution-0.19-SNAPSHOT-bundle.tar.gz

In distribution/target directory will be produced the selfcontained file for the broker with all dependencies and a running script.