In this article, we will discuss how to install an MQTT broker. An MQTT broker (MQTT is short for Message Queue Telemetry Transport) is responsible for delivering messages in a network from publishers to subscribers.
The broker receives all messages on different topics from different devices, and filters them according to the subscriptions of other devices. Then it forwards the messages to those devices interested in the respective topics.
You can install such a broker on any device. However, for further projects it is useful to use a device that is always powered on so that the broker can handle messages 24/7. Thus, I would suggest to use a single-board computer such as the Raspberry Pi.
Step 1: Get the package
As always, we update our sources and then fetch the correct packages. We also install the mosquitto-clients package, in case we want to subscribe to topics on the broker machine as well.
sudo apt update
sudo apt install -y mosquitto mosquitto-clients
Step 2: Enable the service to run in background
Since I installed mosquitto on a Raspberry Pi, I can enable the service using
sudo systemctl enable mosquitto.service