Drew Bednar 42ca31273c | 3 months ago | |
---|---|---|
.mosquitto | 3 months ago | |
clock | 4 months ago | |
cmd | 3 months ago | |
common | 4 months ago | |
img | 3 months ago | |
scripts | 4 months ago | |
.gitignore | 4 months ago | |
DESIGN_CONCIDERATIONS.md | 3 months ago | |
LICENSE | 4 months ago | |
Makefile | 3 months ago | |
README.md | 3 months ago | |
docker-compose.yaml | 3 months ago | |
go.mod | 3 months ago | |
go.sum | 4 months ago |
README.md
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
Ideally I would like this application to resemble the above design. Conceptually, there
Development
For local development we use Mosquitto 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
Resources:
- Mosquitto Docs
- Mosquitto TLS Tutorial
- Golang MQTT Tutorial
- MQTT as a Service
- Using Wireshark for MQTT Analysis
- Caddy as reverse proxy
- Using Python paho MQTT client with TLS
- ESP32 Micropython MQTT with TLS: Note cert file format for uPy MQTT client needs to be in .der format which is a binary format.
- TLS refresher
- HA Mosquitto in K8s
- Lamport Timestamps Tutorial
- Vector Clocks Lecture