Overview
TheEventBus trait defines the interface for OneClaw’s Layer 3 event system, providing publish-subscribe functionality with topic-based routing and event history.
Location: crates/oneclaw-core/src/event_bus/traits.rs
Event Structure
Event
Events flowing through the bus contain:Event Priority
EventBus Trait
Location:crates/oneclaw-core/src/event_bus/traits.rs:71
Methods
publish()
Publish an event to the bus.
subscribe()
Subscribe a handler to a topic pattern. Returns a subscription ID.
Pattern matching:
"*"- matches all events"sensor.*"- matches “sensor.temperature”, “sensor.humidity”"sensor.temp"- exact match
Some(Event) to publish a response event.
unsubscribe()
Remove a subscription by ID. Returns true if subscription was found and removed.
pending_count()
Get the number of pending events in the queue (for synchronous implementations).
drain()
Process all pending events (synchronous implementations). Returns number of events processed.
recent_events()
Get recent event history for debugging.
Event Builder
Location:crates/oneclaw-core/src/event_bus/traits.rs:40-64
NoopEventBus
Location:crates/oneclaw-core/src/event_bus/traits.rs:92
A no-operation implementation for testing without event infrastructure.
Use Cases
- Sensor data routing: Temperature, motion, humidity events
- Device status monitoring: Connection, health, error events
- Alert generation: Critical threshold violations
- System telemetry: Performance, diagnostics
Related
- DefaultEventBus - Synchronous implementation
- AsyncEventBus - Asynchronous implementation
- Event Pipelines - Declarative event processing