event-stream
Transport-agnostic event streaming for Rust applications.
"event-stream" provides a lightweight abstraction for event-driven architectures with support for:
- Strongly typed events
- Event metadata envelopes
- In-memory pub/sub
- NATS-backed messaging
- Typed subscribers
- Transport-independent domain code
Features
EventStream abstraction
Publishers and subscribers depend on a common trait:
This allows applications to switch between local and distributed transports without changing domain logic.
Event metadata
Every event can carry metadata such as:
- Event ID
- Event version
- Timestamp
- Producer
- Correlation ID
- Trace ID
- User ID
- Session ID
- Audience
Example:
let metadata = new
.with_user_id
.with_correlation_id;
Publishing events
Define an event payload:
Publish:
let event = new;
event.publish.await?;
Subscribing to events
Define a payload:
Create a subscriber:
;
Register:
AuditSubscriber.subscribe(bus.clone()).await?;
Local event stream
Useful for testing and single-process deployments.
let bus = new;
The local implementation provides backpressure by awaiting when subscriber queues are full.
NATS event stream
Connect to a NATS server:
let bus = new;
Publishers and subscribers remain unchanged.
Design goals
- Transport-independent domain events
- Strong typing
- Simple pub/sub API
- Rich event metadata
- Local-first development
- NATS for distributed deployments
License
MIT