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