Skip to main content

EventBus

Struct EventBus 

Source
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

Source

pub fn new(provider: impl EventProvider + 'static) -> Self

Create a new event bus from a provider

Source

pub fn with_schema_registry( provider: impl EventProvider + 'static, registry: Arc<dyn SchemaRegistry>, ) -> Self

Create a new event bus with schema validation

Source

pub fn set_dlq_handler(&mut self, handler: Arc<dyn DlqHandler>)

Set the dead letter queue handler

Source

pub fn set_encryptor(&mut self, encryptor: Arc<dyn EventEncryptor>)

Set the payload encryptor

Source

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.

Source

pub fn state_store(&self) -> Option<&dyn StateStore>

Get the state store (if configured)

Source

pub fn metrics(&self) -> &EventMetrics

Get the metrics handle

Use metrics().snapshot() for a point-in-time view of all counters.

Source

pub fn encryptor(&self) -> Option<&dyn EventEncryptor>

Get the encryptor (if configured)

Source

pub fn dlq_handler(&self) -> Option<&dyn DlqHandler>

Get the DLQ handler (if configured)

Source

pub fn schema_registry(&self) -> Option<&dyn SchemaRegistry>

Get the schema registry (if configured)

Source

pub fn provider_name(&self) -> &str

Get the provider name

Source

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.

Source

pub fn broker(&self) -> Option<&Broker>

Get the broker (if configured)

Source

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.

Source

pub async fn publish( &self, category: &str, topic: &str, summary: &str, source: &str, payload: Value, ) -> Result<Event>

Publish an event with convenience parameters

Source

pub async fn publish_event(&self, event: &Event) -> Result<u64>

Publish a pre-built event

Source

pub async fn publish_event_with_options( &self, event: &Event, opts: &PublishOptions, ) -> Result<u64>

Publish a pre-built event with provider-specific options

Source

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.

Source

pub async fn counts(&self, limit: usize) -> Result<EventCounts>

Get event counts by category

Source

pub async fn update_subscription( &self, filter: SubscriptionFilter, ) -> Result<()>

Register or update a subscription

Auto-saves to state store if configured.

Source

pub async fn create_subscriber( &self, subscriber_id: &str, ) -> Result<Vec<Box<dyn Subscription>>>

Create subscribers for a registered subscription

Source

pub async fn remove_subscription(&self, subscriber_id: &str) -> Result<()>

Remove a subscription

Auto-saves to state store if configured.

Source

pub async fn list_subscriptions(&self) -> Vec<SubscriptionFilter>

Get all registered subscriptions

Source

pub async fn get_subscription( &self, subscriber_id: &str, ) -> Option<SubscriptionFilter>

Get a specific subscription

Source

pub async fn info(&self) -> Result<ProviderInfo>

Get provider info

Source

pub fn provider(&self) -> &dyn EventProvider

Get a reference to the underlying provider

Source

pub async fn health(&self) -> Result<bool>

Health check — returns true if the provider is connected and operational

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more