Event Bus Architecture & Async Messaging
The Event Bus (pkg/eventbus/eventbus.go) is RUSEON Core's high-throughput asynchronous message broker. It provides a thread-safe publish-subscribe backbone that enables loose coupling between the high-throughput video streaming core and background webhook/MQTT notification services.
1. FNV-1a Consistent Hashing & In-Order Delivery
To guarantee that camera state events (online, offline, segment_ready) are delivered in strict chronological order without global lock contention:
- The bus routes events to worker goroutines (4 workers by default) using FNV-1a consistent hashing on
camera_id. - All events for a specific camera are processed sequentially by the same worker channel (
chan Eventwith 1,000-event buffer).
2. Circuit Breaker Protection (30s Fail-Safe)
To prevent slow or unreachable webhook endpoints from exhausting worker threads:
- Webhook HTTP requests use a strict 3-second timeout.
- If an endpoint fails (connection error or HTTP 5xx), the Circuit Breaker trips for that URL, suppressing further requests for 30 seconds.
- When the 30-second backoff expires, the next event tests the endpoint; upon success, the circuit breaker resets automatically.
3. Non-Blocking Drop-Newest Semantics & Metrics
When a worker channel reaches maximum capacity (1,000 events):
- The bus drops incoming events non-blockingly using
select ... default. - The global Prometheus counter
ruseon_eventbus_drops_totalis incremented. - Stream ingestion and live viewers are completely protected from downstream webhook latency.