Skip to main content

Crate anycms_event

Crate anycms_event 

Source
Expand description

§anycms-event

A thread-safe, async event bus system for AnyCMS built on tokio broadcast channels.

§Quick Start

use anycms_event::prelude::*;

#[derive(Clone, Debug, Serialize, Deserialize)]
struct UserCreated {
    user_id: u64,
    name: String,
}

impl Event for UserCreated {
    fn event_name() -> &'static str { "user.created" }
}

#[tokio::main]
async fn main() {
    let bus = EventBus::new();

    bus.subscribe(|event: UserCreated| async move {
        println!("User created: {}", event.name);
        Ok(())
    }).await.unwrap();

    bus.publish(UserCreated { user_id: 1, name: "Alice".into() }).await.unwrap();
}

Re-exports§

pub use error::EventBusError;
pub use error::Result;
pub use event::Event;
pub use bus::EventBus;
pub use trigger::RuleStorage;

Modules§

builder
EventBusBuilder 用于构建带配置的 EventBus。
bus
The core EventBus implementation.
error
Error types for the event bus system.
event
Core Event trait definition.
execution_log
事件执行日志模块,提供事件发布和 Handler 执行的记录与查询能力。
prelude
Convenience re-exports for common event bus types.
registry
事件注册表模块,提供事件类型的注册、查询和发现能力。
telemetry
遥测接口,用于监控事件总线的发布/订阅生命周期。
topic
Topic pattern matching for event routing.
transport
Transport abstraction for distributed event bus.
trigger
触发规则引擎模块,提供基于事件模式的动态规则触发能力。

Macros§

event_bus
Define a typed event bus with events and topic groupings.

Derive Macros§

Event
Derive macro for the Event trait.