Digital Twinning: Stand Up an MQTT Broker
![Digital Twin](https://i0.wp.com/davidjmcclelland.com/wp-content/uploads/2023/01/IMG_3238.jpg?resize=204%2C272&ssl=1)
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.
![Docker Logo](https://i0.wp.com/davidjmcclelland.com/wp-content/uploads/2023/01/docker-vector-logo.png?resize=117%2C65&ssl=1)
LF Edge recommends installing Foundry via Docker. Each microservice is configured in it’s own image and it simply works out of the box.
![](https://i0.wp.com/davidjmcclelland.com/wp-content/uploads/2023/01/image.png?resize=193%2C201&ssl=1)
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.
![](https://i0.wp.com/davidjmcclelland.com/wp-content/uploads/2023/01/image-1.png?resize=199%2C191&ssl=1)