You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
learn_mqtt_go/README.md

89 lines
2.5 KiB
Markdown

# Learn MQTT with Go
Learning MQTT with Golang by doing. This repo is a simple example of using a Golang application as a client (pub & sub) of an MQTT broker.
1883, Eclipse Mosquitto unsecured (opening the port on the internet is not recommended).
## Architecture
![mqtt-arch](./img/mqtt-architecture.svg)
Ideally I would like this application to resemble the above design. Conceptually, there
## Development
For local development we use [Mosquitto](https://mosquitto.org/) as our MQTT broker, with TLS enabled.
```
sudo apt install mosquitto-clients
```
First generate local development certs using:
```
make gen-local-tls-certs
```
This will create CA, server, and client certificates suitable for local development. Server and CA certs are created in `./.mosquitto/certs`. The client cert is create in the project root.
Start the local development environment with:
```
make start-dev
```
Stop the local development environment with:
```
make stop-dev
```
### Testing
Unit tests can be run with:
```
make test
```
Integration tests are run via:
```
make test-integration
```
## Usage
To run the application end to end first start the development server:
```
make start-dev
```
Next we can start our subscriber. The following command connects to the TLS listener port.
```
go run cmd/subscriber/main.go --host 0.0.0.0 --port 8883
```
## Design Considerations
See [DESIGN_CONCIDERATIONS.md](./DESIGN_CONCIDERATIONS.md)
## Resources:
- [Mosquitto Docs](https://mosquitto.org/man/mosquitto-8.html)
- [Mosquitto TLS Tutorial](https://cedalo.com/blog/mqtt-tls-configuration-guide/)
- [Golang MQTT Tutorial](https://www.emqx.com/en/blog/how-to-use-mqtt-in-golang)
- [MQTT as a Service](https://cedalo.com/mqtt-broker-pro-mosquitto/)
- [Using Wireshark for MQTT Analysis](https://cedalo.com/blog/wireshark-mqtt-guide/)
- [Caddy as reverse proxy](https://github.com/caddyserver/caddy)
- [Using Python paho MQTT client with TLS](https://cedalo.com/blog/configuring-paho-mqtt-python-client-with-examples/)
- [ESP32 Micropython MQTT with TLS](https://dev.to/bassparanoya/esp32-micropython-mqtt-tls-28fd): Note cert file format for uPy MQTT client needs to be in .der format which is a binary format.
- [TLS refresher](http://www.steves-internet-guide.com/ssl-certificates-explained/)
- [HA Mosquitto in K8s](https://sko.ai/blog/how-to-run-ha-mosquitto/)
- [Lamport Timestamps Tutorial](https://towardsdatascience.com/understanding-lamport-timestamps-with-pythons-multiprocessing-library-12a6427881c6)
- [Vector Clocks Lecture](https://www.youtube.com/watch?v=x-D8iFU1d-o)