Mosquitto & Event Streaming
Architect robust, event-driven microservices using Eclipse Mosquitto for high-performance MQTT messaging.
Why MQTT?
MQTT is a lightweight, publish-subscribe network protocol that transports messages between devices. In the GO-DUCK ecosystem, we use Eclipse Mosquitto as our primary message broker for ultra-low latency event streaming and internal service notifications.
The Messaging Package
GO-DUCK generates a clean messaging package that abstracts the MQTT client (Eclipse Paho). It handles reconnect strategies, certificate-based TLS (optional), and asynchronous publishing.
Audit Streaming: By default, if @Audited is used in GDL, GO-DUCK streams all entity change events to the MQTT topic audit/logs/go-duck-master-app for real-time consumption by external analytics or notification engines.
Publishing an Event
import "go-duck-master-app/messaging"
// Publishing a custom JSON event
event := map[string]interface{}{"event": "user_signed_up", "email": "dev@goduck.io"}
messaging.Publish("events/users", event)
Local Development
Your docker-compose.yml includes a pre-configured Mosquitto image. You can use any MQTT client (like MQTT.fx or mosquitto_pub/sub) to listen to your service events.
# Subscribe to all audit events locally
mosquitto_sub -h localhost -p 1883 -t "audit/logs/#" -v
Interactive Swagger Console
GO-DUCK's automatically generated Swagger UI features a built-in Interactive MQTT Topics Dictionary. By connecting via WebSockets, it allows authenticated users to dynamically SUBSCRIBE to event streams or PUBLISH payloads directly from the documentation interface!
Note: Ensure your Mosquitto broker is configured to accept WebSocket connections (default port 9001) for this feature to work.