Internal Event Bus & Architecture
The Internal Event Bus (internal/events/bus.go) is the central nervous system of RUSEON Core. It decouples the core video streaming pipeline from asynchronous background tasks (such as database indexing, MQTT publishing, webhook dispatching, and Web UI notification broadcasting).
1. Topic Hierarchy & Wildcard Subscriptions
The event bus supports hierarchical dot-separated topic names and wildcard matching:
camera.connected— Specific event topic.camera.*— Matches all camera events (e.g.camera.connected,camera.disconnected,camera.reconnecting).recording.*— Matches all archiver events (e.g.recording.started,recording.segment_closed,recording.pruned).ai.*— Matches all AI detection and classification events.
2. Non-Blocking Dispatch & Isolation
To guarantee that a slow consumer (such as a blocked network connection to an external webhook receiver) never delays video frame routing:
- Buffered Go Channels: Each consumer receives its own independent buffered channel.
- Non-Blocking Select: The bus publishes via
select ... defaultblocks:goselect { case sub.channel <- event: // Successfully queued default: // Channel full: drop event for slow subscriber & increment drop counter atomic.AddUint64(&sub.droppedCount, 1) } - Zero Impact on Streaming: Live WebRTC video streams and RTSP ingest continue processing with microsecond latency regardless of event subscriber saturation.
3. Web UI Integration via Server-Sent Events (SSE)
The browser web dashboard subscribes to real-time events via an SSE endpoint:
bash
GET /api/v1/events/stream
Authorization: Bearer <TOKEN>Sample SSE stream response:
text
event: camera.offline
data: {"camera_id":"cam_entrance","timestamp":1786802400,"reason":"timeout"}
event: ai.detection
data: {"camera_id":"cam_entrance","class":"person","confidence":0.96}