Files
mytheclipse/crates/mytheclipse-event
asepharyana 19941156b4 fix(ci): gate event crate doctest behind mem feature and apply rustfmt
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.
2026-08-28 22:41:06 +07:00
..
2026-08-28 15:30:52 +00:00

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 same EventBus trait, so swapping the backend doesn't change handler code.
  • Typed convenience — TypedEventBus layers JSON encoding on top.

Features

  • mem (default) — in-memory dispatcher.
  • amqp — RabbitMQ via lapin (pure Rust AMQP 0.9.1 client).
  • nats — NATS via async-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.