Skip to content

Event Bus

The internal Event Bus (pkg/eventbus/eventbus.go) provides asynchronous, non-blocking message routing across RUSEON Core subsystems.


Event Schema

Every event emitted across the bus implements the Event struct:

go
type Event struct {
    ID          string                 `json:"id"`
    TimestampMs int64                  `json:"timestamp_ms"`
    Topic       string                 `json:"topic"`
    CameraID    string                 `json:"camera_id,omitempty"`
    Data        map[string]interface{} `json:"data,omitempty"`
}

Official Event Topics

TopicTrigger ConditionPayload Keys (Data)
camera_onlineRTSP client connected and receiving video frames.id
camera_offlineRTSP stream dropped or failed to connect.id, error
archive_segment_ready1-hour or stopped fMP4 recording finalized on disk.camera_id, file, duration
recording_failedFilesystem write error occurred during recording.camera_id, error
storage_warningDisk storage utilization exceeded 90% threshold.used_percent, path

Sequential Consistency & Worker Pools

To prevent race conditions (such as a camera_offline event overtaking a preceding camera_online event), RUSEON Core uses consistent hashing (FNV-1a) on CameraID:

  • Events for the same camera are always routed to the same dedicated worker goroutine.
  • Default worker pool size: 4 workers, each with a channel buffer of 1,000 events.

Backpressure & Drop Policy

The Event Bus enforces a strict Drop-Newest backpressure policy:

  • If a worker queue is saturated (e.g., slow HTTP webhook endpoints), incoming events for that worker are dropped to safeguard video streaming and recording.
  • All drops increment the ruseon_eventbus_drops_total Prometheus counter.

Released under the MIT License.