The crate-root doctest used InMemoryEventBus/TypedEventBus (gated behind
the 'mem' feature), so `cargo test -p mytheclipse-event --no-default-features
--features amqp|nats` failed to compile the doctest (E0432). The example is
now no_run with the mem-dependent imports inside a #[cfg(feature="mem")]
main, so it compiles (and runs) when mem is on and degrades to an empty main
when off.
Also apply rustfmt to mytheclipse-config/dynamic.rs and
mytheclipse-storage/{gcs,s3}.rs to satisfy cargo fmt --all --check.
mytheclipse-event
A unified events & message bus abstraction so component-to-component (or service-to-service) communication isn't locked to one transport.
- In-memory dispatcher (default) —
tokio::sync::broadcast-backed pub/sub for communication inside a single process (monolith). - Distributed broker backends — RabbitMQ (
amqp) and NATS (nats) behind the sameEventBustrait, so swapping the backend doesn't change handler code. - Typed convenience —
TypedEventBuslayers JSON encoding on top.
Features
mem(default) — in-memory dispatcher.amqp— RabbitMQ vialapin(pure Rust AMQP 0.9.1 client).nats— NATS viaasync-nats.
Usage
use mytheclipse_event::{InMemoryEventBus, TypedEventBus};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct OrderCreated { id: u64 }
let bus = TypedEventBus::new(InMemoryEventBus::default());
let mut sub = bus.subscribe::<OrderCreated>("orders").await?;
bus.publish("orders", &OrderCreated { id: 42 }).await?;
let event = sub.recv().await?;
Swap InMemoryEventBus::default() for AmqpEventBus::connect(url, "exchange").await?
or NatsEventBus::connect(url).await? to move to a distributed broker without
touching handler code.