Mosquitto is a lightweight open source message broker that Implements MQTT versions 3.1.0, 3.1.1 and version 5.0
It is written in C by Roger Light, and is available as a free download for Windows and Linux and is an Eclipse project.
The main website is here.
MQTT Version 5.0 Support Notes:
As of release 1.6 the mosquitto broker supports MQTT v5 in addition to MQTT v3.11.
You can continue to use the older version 3.11 clients with the latest broker.
Mosquitto v2 introduced some important changes that affect first time users in particular.
By default it requires authentication and doesn’t listen on a network address.
The following simple configuration file will make mosquitto start like previous versions:
listener 1883 allow_anonymous true
Installing The Broker
To use it you will first need to install it.
Special Note dec 12-2020: The latest version 2.x departs considerably from previous 1.6 versions in the install security and so for beginners I would recommend you stay with the older 1. x versions for the time being.
- How to Install The Mosquitto MQTT Broker on Linux (Ubuntu)
- How to Install The Mosquitto MQTT Broker on Windows
Starting and Stopping The Broker
Depending on the install it will probably be started automatically on system startup.
Although this is very desirable in production environments it is less so in test environments.
My preferred approach is to stop the mosquitto service and start it manually from the command prompt.
This gives you access to the console which is invaluable for testing.
On Windows you can stop the service if it is running by using the control panel>admin>services.
You can also the net command:
net stop mosquitto
On Linux use:
sudo service mosquitto stop sudo systemctl stop mosquitto.service
Starting from command line is the best option when testing and to do that use:
Windows and LInux
mosquitto -v #start in verbose mode
To see other start options use:
By default the broker will start listening on port 1883.
You can change that by editing the configuration file-mosquitto.conf. See Quick Guide to The Mosquitto.conf File With Examples
Alternatively you can use a command line switch to specify the port e.g.
mosquitto -p 1884
You can run Multiple brokers on the same machine by starting them on different ports See this video- on running multiple brokers.
Mosquitto Client Programs
The mosquitto install includes the client testing programs.
There is a simple subscriber client
and a publisher client
They are useful for some quick tests.
Common Questions and Answers
Q- Are messages stored on the broker?
A- Yes but only temporarily. Once they have been sent to all subscribers they are then discarded.
Q -Is there a limit to the message size allowed by a broker?
A- MQTT imposes a maximum message size limit of 268,435,456 bytes. You can restrict the maximum message size the broker will accept using:
in the mosquitto configuration file. Messages received greater than the limit are dropped by the broker.
Q- Does the broker need a configuration file to start?
Q- What is the persistence setting in the mosquitto conf file?
A- When enabled the broker stores temporary data like persistent connections,retained messages,last will messages to a file. If the server is restarted then the values are restored.
- Creating and Using Client Certificates with MQTT and Mosquitto
- How to Install The Mosquitto Broker Windows XP
- Configure Mosquitto Bridge With SSL Encryption
- Quick Guide to The Mosquitto.conf File With Examples
- Mosquitto MQTT Bridge-Usage and Configuration
- Understanding and Configuring Logging – Mosquitto Broker Configuration
- Mosquitto SSL Configuration -MQTT TLS Security
- Configuring and Testing Mosquitto MQTT Topic Restrictions
- Mosquitto Username and Password Authentication -Configuration and Testing
- Using the Mosquitto_ctrl Tool
- Using the mosquitto_pub and mosquitto_sub client tools
- How to Run Multiple mosquitto brokers on the same machine