Skip to main content

EventBusBuilder

Struct EventBusBuilder 

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

EventBus 构建器,提供流畅的配置 API。

§Example

use anycms_event::prelude::*;
use anycms_event::telemetry::TracingTelemetry;
use anycms_event::registry::EventRegistry;

let registry = Arc::new(EventRegistry::new());
let bus = EventBus::builder()
    .capacity(2048)
    .telemetry(TracingTelemetry)
    .registry(registry)
    .build();

Implementations§

Source§

impl EventBusBuilder

Source

pub fn new() -> Self

创建一个新的构建器,使用默认值。

默认容量为 1024,无遥测,自动创建空注册表。

Source

pub fn capacity(self, capacity: usize) -> Self

设置广播通道容量。

容量控制慢订阅者开始被滞后(丢弃旧消息)之前可以缓冲多少消息。

Source

pub fn telemetry<T: Telemetry>(self, telemetry: T) -> Self

设置遥测层。

遥测回调将在事件总线的发布/订阅生命周期中被调用。

Source

pub fn registry(self, registry: Arc<EventRegistry>) -> Self

设置自定义事件注册表。

如果不设置,构建时会自动创建一个空注册表。

Source

pub fn execution_log(self, log: Arc<ExecutionLog>) -> Self

设置执行日志。

执行日志记录事件发布和 Handler 执行的历史记录。 通常与 ExecutionLogTelemetry 一起使用。

Source

pub fn retry_policy(self, policy: RetryPolicy) -> Self

设置 Handler 重试策略。

默认不重试(max_retries: 0)。

Source

pub fn dead_letter_handler<H: DeadLetterHandler>(self, handler: H) -> Self

设置死信处理器。

当 Handler 重试耗尽后,将调用死信处理器。

Source

pub fn build(self) -> EventBus

消费构建器并返回配置好的 EventBus

Trait Implementations§

Source§

impl Default for EventBusBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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