MQTT X Events Skill - File Structure
This directory contains a complete skill for implementing event-driven patterns in MQTT X applications.
- SKILL.md - Main skill documentation with comprehensive guide, examples, and best practices
- Event types and when to use them
- Multiple event handling patterns
- Complete working examples
- Common issues and solutions
- Performance considerations
-
single-event.go.tmpl - Simple single event handler example
- Basic event registration
- Connection monitoring
- Good starting point for beginners
-
event-handling.go.tmpl - Complete event handling demonstration
- All lifecycle events
- Event logger implementation
- State tracking system
- Real-world patterns
-
event-driven.go.tmpl - Advanced event-driven architecture
- Complete reactive system
- Internal event bus
- Health monitoring
- Workflow automation
- Production-ready patterns
Reference Documentation (references/)
-
event-types.md - Complete event type reference
- All 9+ event types documented
- Data structures for each event
- When each event fires
- Use cases and examples
- Best practices
- Event flow diagrams
-
quick-reference.md - Quick lookup guide
- Event constants table
- Common code snippets
- Data structure quick ref
- Pattern cookbook
- Tips and tricks
- Start with SKILL.md - Read "When to Use This Skill" and "Instructions"
- Review references/quick-reference.md for event types
- Copy assets/single-event.go.tmpl as your starting point
- Refer to SKILL.md examples as you build
- Review SKILL.md - Focus on "Common Patterns" section
- Use assets/event-handling.go.tmpl as template
- Customize event handlers for your use case
- Reference references/event-types.md for detailed event info
- Study assets/event-driven.go.tmpl for architecture patterns
- Implement custom event bus and workflows
- Use references/event-types.md for edge cases
- Build production-ready reactive systems
Event Types Quick Summary
| Event | When | Common Use |
|---|
| EventSessionConnecting | Starting connection | Show "connecting" status |
| EventSessionConnected | Successfully connected | Announce presence, start publishing |
| EventSessionDisconnected | Connection lost | Alert, cleanup resources |
| EventSessionReconnecting | Attempting reconnect | Monitor retry attempts |
| EventSessionReady | Connected + subscriptions ready | Start operations safely |
| EventSessionAdded | Session added to manager | Initialize monitoring |
| EventSessionRemoved | Session removed | Cleanup resources |
| EventSessionForceDisconnected | Forced disconnect | Audit administrative actions |
| EventStateChanged | State transition | Detailed state tracking |
- Track connection uptime
- Alert on disconnections
- Monitor reconnection attempts
- Health checks
- Publish on connect
- Resubscribe on reconnect
- Sync state after connection
- Trigger post-connection tasks
- Track all state transitions
- Log connection events
- Monitor session lifecycle
- Troubleshoot connectivity issues
- Implement custom retry logic
- Handle circuit breaker events
- Coordinate multi-session operations
- Graceful degradation
Choose the right template for your needs:
Single Event Handler (single-event.go.tmpl)
├── Lines: ~70
├── Complexity: Low
├── Best for: Simple monitoring, learning basics
└── Features: Basic connection event handling
Multiple Event Handler (event-handling.go.tmpl)
├── Lines: ~400
├── Complexity: Medium
├── Best for: Production monitoring, comprehensive tracking
└── Features: All events, state tracking, event logging, summaries
Event-Driven Architecture (event-driven.go.tmpl)
├── Lines: ~500+
├── Complexity: High
├── Best for: Complex systems, reactive architectures
└── Features: Event bus, workflows, health monitoring, full system
This skill is based on these source files:
/workspace/event.go - Event manager implementation
/workspace/types.go - Event type constants and structures
/workspace/session.go - Event emission in session lifecycle
/workspace/manager.go - Manager-level events
/workspace/examples/advanced_client/advanced_client.go - Real-world usage
- Check SKILL.md Common Issues
- Review Event Types Reference
- Study template examples in
assets/
- Examine source examples in
/workspace/examples/
When updating this skill:
- Keep SKILL.md as the authoritative guide
- Update event-types.md when new events are added
- Maintain templates with working, tested code
- Keep quick-reference.md in sync with changes