use crate::DomainEvent;
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DeliveryMetadata {
event_id: String,
correlation_id: Option<String>,
causation_id: Option<String>,
}
impl DeliveryMetadata {
pub fn new(event_id: impl Into<String>) -> Self {
Self {
event_id: event_id.into(),
correlation_id: None,
causation_id: None,
}
}
pub fn with_correlation_id(mut self, id: impl Into<String>) -> Self {
self.correlation_id = Some(id.into());
self
}
pub fn with_causation_id(mut self, id: impl Into<String>) -> Self {
self.causation_id = Some(id.into());
self
}
pub fn event_id(&self) -> &str {
&self.event_id
}
pub fn correlation_id(&self) -> Option<&str> {
self.correlation_id.as_deref()
}
pub fn causation_id(&self) -> Option<&str> {
self.causation_id.as_deref()
}
}
pub trait DomainEventDeliveryMetadata: DomainEvent {
fn delivery_metadata(&self) -> Option<&DeliveryMetadata>;
}