pub struct EventEnvelope {Show 13 fields
pub event_id: EventId,
pub stream_id: StreamId,
pub sequence_number: u64,
pub timestamp: OffsetDateTime,
pub correlation_id: CorrelationId,
pub causation_id: Option<CausationId>,
pub conversation_id: ConversationId,
pub process_id: ProcessId,
pub tenant_id: TenantId,
pub workflow_id: WorkflowId,
pub event_type: Box<str>,
pub schema_version: u32,
pub payload: Value,
}Expand description
A single persisted event, wrapped in engine-level metadata.
The envelope separates infrastructure concerns (identity, ordering,
tracing) from domain concerns (the business event payload). The payload
is stored as serde_json::Value so the engine remains domain-agnostic.
§Sequence numbers
sequence_number is 1-based and monotonically increasing per stream.
It is assigned by the EventStore during EventStore::append and
must not be set by callers.
§Immutability
Once persisted, an envelope is never modified. Corrections are modelled as new events.
Fields§
§event_id: EventIdGlobally unique event instance identifier (assigned by store).
stream_id: StreamIdThe stream this event belongs to (e.g. process/xxxxxxxx).
sequence_number: u641-based monotonic position within the stream (assigned by store).
timestamp: OffsetDateTimeWall-clock time at which the event was appended to the store (assigned by store).
correlation_id: CorrelationIdGroups all events that originate from the same root command.
causation_id: Option<CausationId>The event or command that directly caused this event, if any.
conversation_id: ConversationIdLinks events belonging to the same business conversation (e.g. a UTILMD exchange and its APERAK acknowledgement).
process_id: ProcessIdStable identifier for the MaKo process instance that owns this stream.
tenant_id: TenantIdTenant that owns this event (market participant or deployment tenant).
workflow_id: WorkflowIdIdentifies the workflow definition (name + BDEW format version) that produced this event.
event_type: Box<str>Stable, human-readable type discriminant for the domain event
(e.g. "SupplierChangeInitiated").
Used for projection routing and observability without deserializing the full payload.
schema_version: u32Schema version of the serialized payload. Increment when the payload structure changes to enable upcasting during replay.
payload: ValueThe domain event payload, serialized as JSON.
Implementations§
Source§impl EventEnvelope
impl EventEnvelope
Sourcepub fn decode<T: DeserializeOwned>(&self) -> Result<T, Error>
pub fn decode<T: DeserializeOwned>(&self) -> Result<T, Error>
Deserialize the payload into a typed domain event.
Clones the serde_json::Value payload and deserializes T from it
directly. Use EventEnvelope::decode_owned to consume the envelope
and avoid the clone when the envelope is no longer needed.
§Errors
Returns a serde_json::Error when deserialization fails.
Sourcepub fn decode_owned<T: DeserializeOwned>(self) -> Result<T, Error>
pub fn decode_owned<T: DeserializeOwned>(self) -> Result<T, Error>
Deserialize the payload into a typed domain event, consuming the envelope to avoid an extra clone.
Prefer this over EventEnvelope::decode when you no longer need
access to the envelope after decoding (e.g. in one-shot projection
handlers that transform each event exactly once).
§Errors
Returns a serde_json::Error when deserialization fails.
Sourcepub fn from_new(
new: NewEvent,
stream_id: StreamId,
sequence_number: u64,
timestamp: OffsetDateTime,
) -> Self
pub fn from_new( new: NewEvent, stream_id: StreamId, sequence_number: u64, timestamp: OffsetDateTime, ) -> Self
Construct an envelope from a NewEvent with store-assigned fields.
Called internally by EventStore implementations during append.
Source§impl EventEnvelope
impl EventEnvelope
Sourcepub fn new_caused_event<E: EventPayload>(
&self,
workflow_id: WorkflowId,
event: &E,
) -> Result<NewEvent, EngineError>
pub fn new_caused_event<E: EventPayload>( &self, workflow_id: WorkflowId, event: &E, ) -> Result<NewEvent, EngineError>
Build a NewEvent causally linked to this envelope.
Propagates correlation_id, conversation_id, process_id, and
tenant_id from the envelope and sets envelope.event_id as the
causation_id of the new event. Useful when generating a follow-up
event (e.g. an APERAK trigger event) that must be traceable back to
the UTILMD envelope that caused it.
§Errors
Returns EngineError::Serialization when the event payload cannot be
serialized to JSON.
§Example
// After persisting a UTILMD receive event, trigger an APERAK:
let aperak_new = utilmd_envelope.new_caused_event(
workflow_id,
&SupplierChangeEvent::AperakDispatched { positive: true, reason: None },
)?;Trait Implementations§
Source§impl Clone for EventEnvelope
impl Clone for EventEnvelope
Source§fn clone(&self) -> EventEnvelope
fn clone(&self) -> EventEnvelope
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more