logo
Public
0
0
WeChat Login
✨ docs: 添加 MQTT X Claude Code Skills 文档

MQTT X Events Skill - File Structure

This directory contains a complete skill for implementing event-driven patterns in MQTT X applications.

Files Overview

Core Documentation

  • 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

Templates (assets/)

  1. single-event.go.tmpl - Simple single event handler example

    • Basic event registration
    • Connection monitoring
    • Good starting point for beginners
  2. event-handling.go.tmpl - Complete event handling demonstration

    • All lifecycle events
    • Event logger implementation
    • State tracking system
    • Real-world patterns
  3. event-driven.go.tmpl - Advanced event-driven architecture

    • Complete reactive system
    • Internal event bus
    • Health monitoring
    • Workflow automation
    • Production-ready patterns

Reference Documentation (references/)

  1. 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
  2. quick-reference.md - Quick lookup guide

    • Event constants table
    • Common code snippets
    • Data structure quick ref
    • Pattern cookbook
    • Tips and tricks

How to Use This Skill

For Beginners

  1. Start with SKILL.md - Read "When to Use This Skill" and "Instructions"
  2. Review references/quick-reference.md for event types
  3. Copy assets/single-event.go.tmpl as your starting point
  4. Refer to SKILL.md examples as you build

For Intermediate Users

  1. Review SKILL.md - Focus on "Common Patterns" section
  2. Use assets/event-handling.go.tmpl as template
  3. Customize event handlers for your use case
  4. Reference references/event-types.md for detailed event info

For Advanced Users

  1. Study assets/event-driven.go.tmpl for architecture patterns
  2. Implement custom event bus and workflows
  3. Use references/event-types.md for edge cases
  4. Build production-ready reactive systems

Event Types Quick Summary

EventWhenCommon Use
EventSessionConnectingStarting connectionShow "connecting" status
EventSessionConnectedSuccessfully connectedAnnounce presence, start publishing
EventSessionDisconnectedConnection lostAlert, cleanup resources
EventSessionReconnectingAttempting reconnectMonitor retry attempts
EventSessionReadyConnected + subscriptions readyStart operations safely
EventSessionAddedSession added to managerInitialize monitoring
EventSessionRemovedSession removedCleanup resources
EventSessionForceDisconnectedForced disconnectAudit administrative actions
EventStateChangedState transitionDetailed state tracking

Example Use Cases

Monitoring & Alerting

  • Track connection uptime
  • Alert on disconnections
  • Monitor reconnection attempts
  • Health checks

Reactive Workflows

  • Publish on connect
  • Resubscribe on reconnect
  • Sync state after connection
  • Trigger post-connection tasks

Debugging & Logging

  • Track all state transitions
  • Log connection events
  • Monitor session lifecycle
  • Troubleshoot connectivity issues

Resilience & Recovery

  • Implement custom retry logic
  • Handle circuit breaker events
  • Coordinate multi-session operations
  • Graceful degradation

Template Selection Guide

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

Related Source Code

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

Navigation

Need Help?

  1. Check SKILL.md Common Issues
  2. Review Event Types Reference
  3. Study template examples in assets/
  4. Examine source examples in /workspace/examples/

Contributing

When updating this skill:

  1. Keep SKILL.md as the authoritative guide
  2. Update event-types.md when new events are added
  3. Maintain templates with working, tested code
  4. Keep quick-reference.md in sync with changes