pub struct Event<PT> {
pub id: EventId,
pub idempotency_token: Option<IdempotencyToken>,
pub event_type: EventType,
pub payload: Payload<PT>,
pub created_at: OffsetDateTime,
pub locked_until: OffsetDateTime,
pub status: EventStatus,
}Expand description
A single outbox row representing one domain event to be published.
An event starts out with status set to
EventStatus::Pending and travels through the worker loop:
a worker flips the row to EventStatus::Processing with a lock until
locked_until, publishes via the transport, and
finally marks it EventStatus::Sent. If a worker crashes, the lock
expires and the row becomes eligible again.
Generic over the user’s payload type PT; see Payload.
Fields§
§id: EventIdRandomly generated primary key (UUID v4). Used to identify the row across status transitions.
idempotency_token: Option<IdempotencyToken>Deduplication token produced according to the configured
IdempotencyStrategy. May be
None when no token is produced.
event_type: EventTypeDomain-level event name used for routing on the transport side.
payload: Payload<PT>The user payload, serialized as JSON when the sqlx feature is on.
created_at: OffsetDateTimeWall-clock time the row was constructed, in UTC.
locked_until: OffsetDateTimeExpiration of the current processing lock. Fresh rows start with
OffsetDateTime::UNIX_EPOCH (i.e. “not locked”); storage adapters
update this when they claim the row for processing.
status: EventStatusCurrent lifecycle stage. See EventStatus.
Implementations§
Source§impl<PT> Event<PT>
impl<PT> Event<PT>
Sourcepub fn new(
event_type: EventType,
payload: Payload<PT>,
idempotency_token: Option<IdempotencyToken>,
) -> Self
pub fn new( event_type: EventType, payload: Payload<PT>, idempotency_token: Option<IdempotencyToken>, ) -> Self
Constructs a new Event ready to be inserted by the storage layer.
The caller supplies the domain-level fields (event_type, payload,
idempotency_token); the remaining fields are initialised with sensible
defaults:
id— a fresh randomEventIdcreated_at—OffsetDateTime::now_utc()locked_until—OffsetDateTime::UNIX_EPOCH(unlocked)status—EventStatus::Pending
Trait Implementations§
Source§impl<'a, R: Row, PT> FromRow<'a, R> for Event<PT>where
&'a str: ColumnIndex<R>,
EventId: Decode<'a, R::Database> + Type<R::Database>,
Option<IdempotencyToken>: Decode<'a, R::Database> + Type<R::Database>,
EventType: Decode<'a, R::Database> + Type<R::Database>,
Json<Payload<PT>>: Decode<'a, R::Database> + Type<R::Database>,
OffsetDateTime: Decode<'a, R::Database> + Type<R::Database>,
EventStatus: Decode<'a, R::Database> + Type<R::Database>,
impl<'a, R: Row, PT> FromRow<'a, R> for Event<PT>where
&'a str: ColumnIndex<R>,
EventId: Decode<'a, R::Database> + Type<R::Database>,
Option<IdempotencyToken>: Decode<'a, R::Database> + Type<R::Database>,
EventType: Decode<'a, R::Database> + Type<R::Database>,
Json<Payload<PT>>: Decode<'a, R::Database> + Type<R::Database>,
OffsetDateTime: Decode<'a, R::Database> + Type<R::Database>,
EventStatus: Decode<'a, R::Database> + Type<R::Database>,
Auto Trait Implementations§
impl<PT> Freeze for Event<PT>where
PT: Freeze,
impl<PT> RefUnwindSafe for Event<PT>where
PT: RefUnwindSafe,
impl<PT> Send for Event<PT>where
PT: Send,
impl<PT> Sync for Event<PT>where
PT: Sync,
impl<PT> Unpin for Event<PT>where
PT: Unpin,
impl<PT> UnsafeUnpin for Event<PT>where
PT: UnsafeUnpin,
impl<PT> UnwindSafe for Event<PT>where
PT: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more