Expand description
§mytheclipse-event
A unified events & message bus abstraction so component-to-component (or service-to-service) communication doesn’t get locked to one transport.
- In-memory dispatcher (
memory::InMemoryEventBus, featuremem, default): atokio::sync::broadcast-backed pub/sub bus for intra-process communication. - Distributed broker backends: [
amqp::AmqpEventBus] (RabbitMQ, featureamqp) and [nats::NatsEventBus] (NATS, featurenats) behind the sameEventBustrait, so swapping the backend does not change handler code. - Typed convenience: [
typed::TypedEventBus] layers JSON (de)serialization on top of the byte-orientedEventBus.
§Example
The in-memory bus (mem feature, on by default) carries raw bytes; the
typed feature adds JSON (de)serialization on top of it.
#[cfg(feature = "mem")]
#[tokio::main]
async fn main() {
use mytheclipse_event::{EventBus, InMemoryEventBus};
let bus = InMemoryEventBus::default();
let mut sub = bus.subscribe("orders").await.unwrap();
bus.publish("orders", b"{\"id\":42}".to_vec()).await.unwrap();
let payload = sub.recv().await.unwrap();
assert_eq!(payload, b"{\"id\":42}");
}
#[cfg(not(feature = "mem"))]
fn main() {}Re-exports§
pub use traits::EventBus;pub use traits::EventError;pub use traits::Subscription;pub use memory::InMemoryEventBus;
Modules§
- memory
- In-memory pub/sub dispatcher (feature
mem), backed bytokio::sync::broadcast. - prelude
- The common case, in one import.
- traits
- The core
EventBustrait and byte-orientedSubscriptionhandle.