Convert Figma logo to code with AI

eclipse-mosquitto logomosquitto

Eclipse Mosquitto - An open source MQTT broker

9,688
2,478
9,688
823

Top Related Projects

14,704

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

3,290

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!

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

Open source RabbitMQ: core server and tier 1 (built-in) plugins

Apache ActiveMQ Classic

Quick Overview

Eclipse Mosquitto is an open-source message broker that implements the MQTT protocol versions 5.0, 3.1.1, and 3.1. It is lightweight and suitable for use on all devices from low power single board computers to full servers, making it ideal for Internet of Things (IoT) messaging.

Pros

  • Lightweight and efficient, suitable for a wide range of devices
  • Supports multiple MQTT protocol versions (5.0, 3.1.1, 3.1)
  • Highly scalable and can handle thousands of concurrent clients
  • Active community and regular updates

Cons

  • Limited built-in security features compared to some commercial alternatives
  • Requires additional setup for advanced features like clustering
  • Documentation can be sparse for some advanced topics
  • May require more manual configuration compared to some managed MQTT services

Code Examples

  1. Connecting to a Mosquitto broker:
import paho.mqtt.client as mqtt

client = mqtt.Client()
client.connect("localhost", 1883, 60)
client.loop_forever()
  1. Publishing a message:
import paho.mqtt.client as mqtt

client = mqtt.Client()
client.connect("localhost", 1883)
client.publish("test/topic", "Hello, Mosquitto!")
client.disconnect()
  1. Subscribing to a topic:
import paho.mqtt.client as mqtt

def on_message(client, userdata, message):
    print(f"Received message: {message.payload.decode()}")

client = mqtt.Client()
client.on_message = on_message
client.connect("localhost", 1883)
client.subscribe("test/topic")
client.loop_forever()

Getting Started

  1. Install Mosquitto:

    sudo apt-get install mosquitto mosquitto-clients
    
  2. Start the Mosquitto service:

    sudo systemctl start mosquitto
    
  3. Install the Paho MQTT client library for Python:

    pip install paho-mqtt
    
  4. Use the code examples above to connect, publish, and subscribe to topics using Mosquitto.

Competitor Comparisons

14,704

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

Pros of EMQX

  • Highly scalable, supporting millions of concurrent MQTT connections
  • Rich features including rule engine, data bridging, and multi-protocol support
  • Built-in clustering for high availability and fault tolerance

Cons of EMQX

  • More complex setup and configuration compared to Mosquitto
  • Higher resource requirements for running and maintaining
  • Steeper learning curve for beginners

Code Comparison

EMQX (Erlang):

-module(emqx_broker).
-export([publish/1]).

publish(Message) ->
    emqx:publish(Message).

Mosquitto (C):

#include "mosquitto.h"

int publish_message(struct mosquitto *mosq, const char *topic, const char *payload) {
    return mosquitto_publish(mosq, NULL, topic, strlen(payload), payload, 0, false);
}

Key Differences

  • EMQX is written in Erlang, while Mosquitto is written in C
  • EMQX offers a more extensive feature set for enterprise-level deployments
  • Mosquitto is lightweight and easier to set up for smaller projects
  • EMQX provides built-in clustering, while Mosquitto requires additional configuration for clustering
  • EMQX has a web-based dashboard for management, whereas Mosquitto relies on command-line tools

Both brokers are open-source and support the MQTT protocol, but they cater to different use cases and deployment scales.

3,290

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

  • Highly scalable and distributed architecture, suitable for large-scale deployments
  • Built-in clustering capabilities for improved fault tolerance and load balancing
  • Extensive plugin system for customization and integration with other services

Cons of VerneMQ

  • Steeper learning curve and more complex configuration compared to Mosquitto
  • Higher resource requirements, which may be overkill for smaller projects
  • Less widespread adoption and community support than Mosquitto

Code Comparison

VerneMQ (Erlang):

vmq_server:start_listener(1883, [{max_connections, 100000},
                                 {nr_of_acceptors, 100},
                                 {mountpoint, ""}]).

Mosquitto (C):

mosquitto_new("client_id", true, NULL);
mosquitto_connect(mosq, "localhost", 1883, 60);
mosquitto_loop_start(mosq);

VerneMQ's code snippet demonstrates its focus on high-performance settings, while Mosquitto's code shows its simplicity in establishing a basic connection.

Both projects are open-source MQTT brokers, but they cater to different use cases. Mosquitto is lightweight and easy to set up, making it ideal for small to medium-sized projects and IoT applications. VerneMQ, on the other hand, is designed for large-scale, distributed systems that require high availability and scalability.

The choice between the two depends on the specific requirements of your project, such as expected load, scalability needs, and available resources for deployment and maintenance.

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

  • Scalable architecture designed for enterprise-level deployments
  • Built-in clustering support for high availability
  • Extensive plugin system for customization and integration

Cons of HiveMQ Community Edition

  • Higher resource requirements compared to Mosquitto
  • Steeper learning curve for configuration and management
  • Limited documentation for the community edition

Code Comparison

Mosquitto configuration example:

listener 1883
protocol mqtt
allow_anonymous true

HiveMQ Community Edition configuration example:

<hivemq>
    <listeners>
        <tcp-listener>
            <port>1883</port>
        </tcp-listener>
    </listeners>
    <anonymous-usage-statistics>
        <enabled>false</enabled>
    </anonymous-usage-statistics>
</hivemq>

Mosquitto is known for its simplicity and lightweight nature, making it ideal for small to medium-sized deployments. It uses a straightforward configuration file format and has a smaller memory footprint.

HiveMQ Community Edition, on the other hand, offers more advanced features suitable for large-scale, enterprise-level implementations. It uses XML-based configuration files, which provide more flexibility but can be more complex to manage.

Both projects are open-source MQTT brokers, but they cater to different use cases and deployment scales. The choice between them depends on the specific requirements of the project, such as scalability needs, resource constraints, and desired features.

Open source RabbitMQ: core server and tier 1 (built-in) plugins

Pros of RabbitMQ Server

  • More feature-rich with advanced routing capabilities and multiple messaging protocols
  • Better scalability and clustering support for high-availability setups
  • Comprehensive management UI and monitoring tools

Cons of RabbitMQ Server

  • Higher resource consumption and complexity compared to Mosquitto
  • Steeper learning curve for configuration and management
  • Less suitable for lightweight IoT applications

Code Comparison

Mosquitto (C):

mosquitto_publish(mosq, NULL, topic, strlen(message), message, 0, false);

RabbitMQ (Erlang):

basic_publish(Channel, <<"">>, RoutingKey, Payload, #'basic.properties'{})

Both examples show a basic message publish operation. Mosquitto's API is simpler and more straightforward, while RabbitMQ's offers more flexibility with routing and message properties.

Mosquitto is lightweight and ideal for MQTT-based IoT scenarios, while RabbitMQ is a more robust, feature-rich message broker suitable for complex enterprise messaging needs. The choice between them depends on specific project requirements, scalability needs, and the desired level of complexity in message routing and management.

Apache ActiveMQ Classic

Pros of ActiveMQ

  • Supports multiple protocols (AMQP, MQTT, STOMP) in addition to its native protocol
  • Offers advanced features like message persistence, clustering, and security
  • Provides a web-based management console for easier monitoring and administration

Cons of ActiveMQ

  • Higher resource consumption and complexity compared to Mosquitto
  • Steeper learning curve and more challenging setup process
  • May be overkill for simpler messaging scenarios or IoT applications

Code Comparison

Mosquitto (C):

mosquitto_publish(mosq, NULL, topic, strlen(message), message, 0, false);

ActiveMQ (Java):

MessageProducer producer = session.createProducer(destination);
TextMessage message = session.createTextMessage(text);
producer.send(message);

Summary

Mosquitto is a lightweight, MQTT-focused broker ideal for IoT and simple messaging scenarios. ActiveMQ is a more feature-rich, multi-protocol message broker suitable for complex enterprise messaging needs. While Mosquitto excels in simplicity and efficiency, ActiveMQ offers advanced features at the cost of increased complexity and resource usage.

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

Eclipse Mosquitto

Mosquitto is an open source implementation of a server for version 5.0, 3.1.1, and 3.1 of the MQTT protocol. It also includes a C and C++ client library, and the mosquitto_pub and mosquitto_sub utilities for publishing and subscribing.

Links

See the following links for more information on MQTT:

Mosquitto project information is available at the following locations:

There is also a public test server available at https://test.mosquitto.org/

Installing

See https://mosquitto.org/download/ for details on installing binaries for various platforms.

Quick start

If you have installed a binary package the broker should have been started automatically. If not, it can be started with a very basic configuration:

mosquitto

Then use mosquitto_sub to subscribe to a topic:

mosquitto_sub -t 'test/topic' -v

And to publish a message:

mosquitto_pub -t 'test/topic' -m 'hello world'

Note that starting the broker like this allows anonymous/unauthenticated access but only from the local computer, so it's only really useful for initial testing.

If you want to have clients from another computer connect, you will need to provide a configuration file. If you have installed from a binary package, you will probably already have a configuration file at somewhere like /etc/mosquitto/mosquitto.conf. If you've compiled from source, you can write your config file then run as mosquitto -c /path/to/mosquitto.conf.

To start your config file you define a listener and you will need to think about what authentication you require. It is not advised to run your broker with anonymous access when it is publically available.

For details on how to do this, look at the authentication methods available and the dynamic security plugin.

Documentation

Documentation for the broker, clients and client library API can be found in the man pages, which are available online at https://mosquitto.org/man/. There are also pages with an introduction to the features of MQTT, the mosquitto_passwd utility for dealing with username/passwords, and a description of the configuration file options available for the broker.

Detailed client library API documentation can be found at https://mosquitto.org/api/

Building from source

To build from source the recommended route for end users is to download the archive from https://mosquitto.org/download/.

On Windows and Mac, use cmake to build. On other platforms, just run make to build. For Windows, see also README-windows.md.

If you are building from the git repository then the documentation will not already be built. Use make binary to skip building the man pages, or install docbook-xsl on Debian/Ubuntu systems.

Build Dependencies

  • c-ares (libc-ares-dev on Debian based systems) - only when compiled with make WITH_SRV=yes
  • cJSON - for client JSON output support. Disable with make WITH_CJSON=no Auto detected with CMake.
  • libwebsockets (libwebsockets-dev) - enable with make WITH_WEBSOCKETS=yes
  • openssl (libssl-dev on Debian based systems) - disable with make WITH_TLS=no
  • pthreads - for client library thread support. This is required to support the mosquitto_loop_start() and mosquitto_loop_stop() functions. If compiled without pthread support, the library isn't guaranteed to be thread safe.
  • uthash / utlist - bundled versions of these headers are provided, disable their use with make WITH_BUNDLED_DEPS=no
  • xsltproc (xsltproc and docbook-xsl on Debian based systems) - only needed when building from git sources - disable with make WITH_DOCS=no

Equivalent options for enabling/disabling features are available when using the CMake build.

Credits

Mosquitto was written by Roger Light roger@atchoo.org