pub struct EventBus { /* private fields */ }Expand description
High-level event bus backed by a pluggable provider
Wraps any EventProvider with subscription tracking and convenience
methods. Thread-safe via internal locks.
Optionally validates events against a SchemaRegistry before publishing.
Optionally encrypts event payloads via an EventEncryptor.
Optionally persists subscription state via a StateStore.
Optionally routes failed events to a DlqHandler.
Implementations§
Source§impl EventBus
impl EventBus
Sourcepub fn new(provider: impl EventProvider + 'static) -> Self
pub fn new(provider: impl EventProvider + 'static) -> Self
Create a new event bus from a provider
Sourcepub fn with_schema_registry(
provider: impl EventProvider + 'static,
registry: Arc<dyn SchemaRegistry>,
) -> Self
pub fn with_schema_registry( provider: impl EventProvider + 'static, registry: Arc<dyn SchemaRegistry>, ) -> Self
Create a new event bus with schema validation
Sourcepub fn set_dlq_handler(&mut self, handler: Arc<dyn DlqHandler>)
pub fn set_dlq_handler(&mut self, handler: Arc<dyn DlqHandler>)
Set the dead letter queue handler
Sourcepub fn set_encryptor(&mut self, encryptor: Arc<dyn EventEncryptor>)
pub fn set_encryptor(&mut self, encryptor: Arc<dyn EventEncryptor>)
Set the payload encryptor
Sourcepub fn set_state_store(&mut self, store: Arc<dyn StateStore>) -> Result<()>
pub fn set_state_store(&mut self, store: Arc<dyn StateStore>) -> Result<()>
Set the state store and load persisted subscriptions
Any previously persisted subscriptions are loaded immediately.
Sourcepub fn state_store(&self) -> Option<&dyn StateStore>
pub fn state_store(&self) -> Option<&dyn StateStore>
Get the state store (if configured)
Sourcepub fn metrics(&self) -> &EventMetrics
pub fn metrics(&self) -> &EventMetrics
Get the metrics handle
Use metrics().snapshot() for a point-in-time view of all counters.
Sourcepub fn encryptor(&self) -> Option<&dyn EventEncryptor>
pub fn encryptor(&self) -> Option<&dyn EventEncryptor>
Get the encryptor (if configured)
Sourcepub fn dlq_handler(&self) -> Option<&dyn DlqHandler>
pub fn dlq_handler(&self) -> Option<&dyn DlqHandler>
Get the DLQ handler (if configured)
Sourcepub fn schema_registry(&self) -> Option<&dyn SchemaRegistry>
pub fn schema_registry(&self) -> Option<&dyn SchemaRegistry>
Get the schema registry (if configured)
Sourcepub fn provider_name(&self) -> &str
pub fn provider_name(&self) -> &str
Get the provider name
Sourcepub fn set_broker(&mut self, broker: Arc<Broker>)
pub fn set_broker(&mut self, broker: Arc<Broker>)
Set the event broker for trigger-based routing
When a broker is configured, all published events are automatically routed through the broker after being published to the provider.
Sourcepub fn provider_arc(&self) -> Arc<dyn EventProvider>
pub fn provider_arc(&self) -> Arc<dyn EventProvider>
Get a shared reference to the underlying provider
Useful for creating TopicSink instances that share the provider.
Sourcepub async fn publish(
&self,
category: &str,
topic: &str,
summary: &str,
source: &str,
payload: Value,
) -> Result<Event>
pub async fn publish( &self, category: &str, topic: &str, summary: &str, source: &str, payload: Value, ) -> Result<Event>
Publish an event with convenience parameters
Sourcepub async fn publish_event(&self, event: &Event) -> Result<u64>
pub async fn publish_event(&self, event: &Event) -> Result<u64>
Publish a pre-built event
Sourcepub async fn publish_event_with_options(
&self,
event: &Event,
opts: &PublishOptions,
) -> Result<u64>
pub async fn publish_event_with_options( &self, event: &Event, opts: &PublishOptions, ) -> Result<u64>
Publish a pre-built event with provider-specific options
Sourcepub async fn list_events(
&self,
category: Option<&str>,
limit: usize,
) -> Result<Vec<Event>>
pub async fn list_events( &self, category: Option<&str>, limit: usize, ) -> Result<Vec<Event>>
Fetch recent events, optionally filtered by category
If an encryptor is configured, encrypted payloads are decrypted automatically.
Sourcepub async fn counts(&self, limit: usize) -> Result<EventCounts>
pub async fn counts(&self, limit: usize) -> Result<EventCounts>
Get event counts by category
Sourcepub async fn update_subscription(
&self,
filter: SubscriptionFilter,
) -> Result<()>
pub async fn update_subscription( &self, filter: SubscriptionFilter, ) -> Result<()>
Register or update a subscription
Auto-saves to state store if configured.
Sourcepub async fn create_subscriber(
&self,
subscriber_id: &str,
) -> Result<Vec<Box<dyn Subscription>>>
pub async fn create_subscriber( &self, subscriber_id: &str, ) -> Result<Vec<Box<dyn Subscription>>>
Create subscribers for a registered subscription
Sourcepub async fn remove_subscription(&self, subscriber_id: &str) -> Result<()>
pub async fn remove_subscription(&self, subscriber_id: &str) -> Result<()>
Remove a subscription
Auto-saves to state store if configured.
Sourcepub async fn list_subscriptions(&self) -> Vec<SubscriptionFilter>
pub async fn list_subscriptions(&self) -> Vec<SubscriptionFilter>
Get all registered subscriptions
Sourcepub async fn get_subscription(
&self,
subscriber_id: &str,
) -> Option<SubscriptionFilter>
pub async fn get_subscription( &self, subscriber_id: &str, ) -> Option<SubscriptionFilter>
Get a specific subscription
Sourcepub async fn info(&self) -> Result<ProviderInfo>
pub async fn info(&self) -> Result<ProviderInfo>
Get provider info
Sourcepub fn provider(&self) -> &dyn EventProvider
pub fn provider(&self) -> &dyn EventProvider
Get a reference to the underlying provider