pub struct EventEnvelope<E: DomainEvent> {
pub id: String,
pub event_type: &'static str,
pub aggregate_id: String,
pub aggregate_type: &'static str,
pub occurred_at: DateTime<Utc>,
pub published_at: DateTime<Utc>,
pub correlation_id: Option<String>,
pub causation_id: Option<String>,
pub version: u32,
pub metadata: HashMap<String, String>,
/* private fields */
}Expand description
Wrapper for domain events with metadata
EventEnvelope adds infrastructure concerns (IDs, timestamps, tracing) around domain events without polluting the domain model.
Fields§
§id: StringUnique event ID
event_type: &'static strEvent type name
aggregate_id: StringAggregate ID this event belongs to
aggregate_type: &'static strAggregate type name
occurred_at: DateTime<Utc>When the event occurred in the domain
published_at: DateTime<Utc>When the event was published to the bus
correlation_id: Option<String>Correlation ID for distributed tracing
causation_id: Option<String>Causation ID (parent event that caused this one)
version: u32Event schema version
metadata: HashMap<String, String>Additional metadata
Implementations§
Source§impl<E: DomainEvent> EventEnvelope<E>
impl<E: DomainEvent> EventEnvelope<E>
Sourcepub fn into_event(self) -> Option<E>
pub fn into_event(self) -> Option<E>
Take ownership of the wrapped event
Sourcepub fn with_correlation_id(self, id: impl Into<String>) -> Self
pub fn with_correlation_id(self, id: impl Into<String>) -> Self
Set correlation ID for distributed tracing
Sourcepub fn with_causation_id(self, id: impl Into<String>) -> Self
pub fn with_causation_id(self, id: impl Into<String>) -> Self
Set causation ID (parent event)
Sourcepub fn with_metadata(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add metadata
Check if this event is correlated with another
Sourcepub fn was_caused_by(&self, other: &Self) -> bool
pub fn was_caused_by(&self, other: &Self) -> bool
Check if this event was caused by another
Trait Implementations§
Source§impl<E: Clone + DomainEvent> Clone for EventEnvelope<E>
impl<E: Clone + DomainEvent> Clone for EventEnvelope<E>
Source§impl<E: Debug + DomainEvent> Debug for EventEnvelope<E>
impl<E: Debug + DomainEvent> Debug for EventEnvelope<E>
Source§impl<E> Deserialize<'static> for EventEnvelope<E>where
E: Default + DomainEvent,
impl<E> Deserialize<'static> for EventEnvelope<E>where
E: Default + DomainEvent,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'static>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'static>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<E: DomainEvent> Serialize for EventEnvelope<E>
impl<E: DomainEvent> Serialize for EventEnvelope<E>
Auto Trait Implementations§
impl<E> Freeze for EventEnvelope<E>
impl<E> RefUnwindSafe for EventEnvelope<E>where
Option<E>: RefUnwindSafe,
impl<E> Send for EventEnvelope<E>
impl<E> Sync for EventEnvelope<E>
impl<E> Unpin for EventEnvelope<E>
impl<E> UnsafeUnpin for EventEnvelope<E>where
Option<E>: UnsafeUnpin,
impl<E> UnwindSafe for EventEnvelope<E>where
Option<E>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more