Skip to main content

EventBus

Struct EventBus 

Source
pub struct EventBus { /* private fields */ }
Expand description

事件总线

事件驱动的核心组件,负责事件的发布和分发。

Implementations§

Source§

impl EventBus

Source

pub fn new(config: EventBusConfig) -> Self

创建新的事件总线

Source

pub fn with_store( config: EventBusConfig, store: Option<Arc<dyn EventStore>>, ) -> Self

创建带事件存储的事件总线

Source

pub fn subscribe<H: EventHandler + 'static>( &self, event_types: Vec<EventTypeName>, handler: H, ) -> WaeResult<Subscription>

订阅事件

注册一个事件处理器,订阅指定类型的事件。

Source

pub fn subscribe_with_filter<H: EventHandler + 'static, F: EventFilter + 'static>( &self, event_types: Vec<EventTypeName>, handler: H, filter: Option<F>, ) -> WaeResult<Subscription>

订阅事件 (带过滤器)

注册一个事件处理器,订阅指定类型的事件,并应用过滤器。

Source

pub fn unsubscribe(&self, subscription_id: &str) -> WaeResult<bool>

取消订阅

移除指定 ID 的订阅。

Source

pub fn publish<E: Event + Serialize>(&self, event: &E) -> WaeResult<()>

发布事件

同步发布事件到事件总线。

Source

pub fn publish_data(&self, event_data: EventData) -> WaeResult<()>

发布事件数据

发布已封装的事件数据。

Source

pub async fn publish_async<E: Event + Serialize>( &self, event: &E, ) -> WaeResult<()>

异步发布事件

异步发布事件到事件总线。

Source

pub async fn publish_data_async(&self, event_data: EventData) -> WaeResult<()>

异步发布事件数据

异步发布已封装的事件数据。

Source

pub fn subscription_count(&self) -> usize

获取订阅数量

Source

pub fn subscription_count_for_type(&self, event_type: &str) -> usize

获取指定事件类型的订阅数量

Source

pub async fn shutdown(&self) -> WaeResult<()>

关闭事件总线

Source

pub async fn replay_events<H: EventHandler + 'static>( &self, store: &dyn EventStore, handler: &H, event_type: Option<&str>, ) -> WaeResult<u64>

事件回放

从事件存储中回放事件到指定处理器。

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, 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<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