Technical Component Specification: EventBus¶
Overview¶
The EventBus
serves as a central event system to be used with the OpsML server to record events. It provides asynchronous event distribution using Tokio's broadcast channel, and it enables decoupled communication between different parts of the system, particularly for audit logging and monitoring.
Component Definition¶
#[derive(Clone)]
pub struct EventBus {
tx: broadcast::Sender<Event>,
}
pub enum Event {
Audit(AuditEvent),
// Extensible for future event types
}
Core Responsibilities¶
- Event Distribution
- Asynchronous event broadcasting
- Multiple subscriber support
- Non-blocking event publishing
-
Event type management
-
Stream Management
- Stream-based event subscription
- Automatic error filtering
- Broadcast channel capacity control
-
Subscriber lifecycle management
-
Event Type Handling
- Support for different event types
- Type-safe event distribution
- Event filtering capabilities
- Extensible event system
Key Methods¶
Constructor¶
Core Operations¶
Dependencies¶
- External Crates
tokio
: Async runtime and broadcast channelfutures
: Stream trait implementationstokio-stream
: Stream wrappers-
tracing
: Logging and instrumentation -
Internal Components
Event
: Event type enumAuditEvent
: Audit event structureEventError
: Error handling
Error Handling¶
- Silent error handling for send operations
- Stream filtering for failed receives
- Debug logging for event operations
- Custom
EventError
type
Thread Safety¶
- Thread-safe event broadcasting
- Clone-able event bus instance
- Safe multi-subscriber support
- Atomic broadcast operations
Performance Considerations¶
- Channel Capacity
-
Configurable buffer size
-
Concurrency
- Non-blocking operations
- Multiple concurrent subscribers
-
Efficient event distribution
-
Resource Management
- Automatic cleanup of dropped subscribers (via Tokio)
- Pattern matching for event types
Future Considerations¶
- Event persistence options
- Priority-based event handling
- Event batching capabilities
- Enhanced filtering mechanisms
- Subscriber backpressure handling
- Event replay functionality
Version: 1.0
Last Updated: 2025-04-04
Component Owner: Steven Forrester