atomr_patterns/ddd/domain_event.rs
1//! [`DomainEvent`] — a fact about something that happened in the domain.
2
3/// A persisted fact. Supplies optional metadata the read side needs:
4///
5/// * [`DomainEvent::tags`] — categorization keys for `events_by_tag`
6/// subscriptions in [`atomr_persistence_query::ReadJournal`].
7/// * [`DomainEvent::correlation_id`] — threads related events across
8/// aggregates so a [`crate::saga::Saga`] can correlate them.
9pub trait DomainEvent: Clone + Send + 'static {
10 /// Tags applied to this event in the journal. Default: none.
11 /// Tags are how readers subscribe to *categories* of events
12 /// instead of specific persistence ids.
13 fn tags(&self) -> Vec<String> {
14 Vec::new()
15 }
16
17 /// Correlation id used by sagas / process managers to thread
18 /// related events together. Default: none — no correlation.
19 fn correlation_id(&self) -> Option<&str> {
20 None
21 }
22}