Digital Twinning: Stand Up an MQTT Broker
An MQTT Broker is any message broker that supports the Oasis MQTT specification. A broker is required to use MQTT. MQTT is a lightweight IoT publish-subscribe system – the broker is the central server listening for, queueing and dispatching messages which come from and are sent to connected devices. It is one of the most long-standing and popular messaging protocols, and it can be used over TCP with WebSockets to maintain a continuous stream of data, which is why I decided to use it.
There are many IoT platforms that support MQTT, including over a dozen that are free open source. I wanted to set up a large-scale system that could provide some potentially relevant experience for future Iot development work. For this reason I chose LF EdgeX Foundry, which is a micro-service based system used in many large-scale implementations. Otherwise I recommend using a free cloud broker service and skipping the installation – HiveMQ has a small-scale free service that is easy to get up and running with.
LF Edge recommends installing Foundry via Docker. Each microservice is configured in it’s own image and it simply works out of the box.
There is an option to install a virtual device with Foundry – this was very helpful in multiple ways:
- I was able to confirm that I was getting messages from my service by switching the virtual device service on and off.
- I could examine the format of the messages and use that to create my own
- I could rely on a steady, but not overwhelming, stream of messages.
- I could immediately see the effect of assigning different topics for the purpose of segregating and filtering streams.
I used the recommended MQTT Websocket page from HiveMQ to verify my service was up and running. Entering the address, port and topic name was enough to confirm that I could publish and receive messages via my broker service: both virtual devices and messages I created and published from the page.