feat: event ids, outbox identity migration
This commit is contained in:
@@ -150,14 +150,44 @@ pub trait AckHandle: Send + Sync {
|
||||
async fn nack(&self) -> Result<(), DomainError>;
|
||||
}
|
||||
|
||||
/// Stable identity of one queued event; the key for de-duplicating deliveries.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct EventId(uuid::Uuid);
|
||||
|
||||
impl EventId {
|
||||
pub fn new() -> Self {
|
||||
Self(uuid::Uuid::new_v4())
|
||||
}
|
||||
|
||||
pub fn from_uuid(uuid: uuid::Uuid) -> Self {
|
||||
Self(uuid)
|
||||
}
|
||||
|
||||
pub fn value(&self) -> uuid::Uuid {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for EventId {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EventEnvelope {
|
||||
pub event: DomainEvent,
|
||||
id: Option<EventId>,
|
||||
ack: Box<dyn AckHandle>,
|
||||
}
|
||||
|
||||
impl EventEnvelope {
|
||||
pub fn new(event: DomainEvent, ack: Box<dyn AckHandle>) -> Self {
|
||||
Self { event, ack }
|
||||
/// `id` is `None` only for events queued before identities existed.
|
||||
pub fn new(id: Option<EventId>, event: DomainEvent, ack: Box<dyn AckHandle>) -> Self {
|
||||
Self { event, id, ack }
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<&EventId> {
|
||||
self.id.as_ref()
|
||||
}
|
||||
|
||||
pub async fn ack(self) -> Result<(), DomainError> {
|
||||
|
||||
Reference in New Issue
Block a user