Skip to main content

EventEnvelope

Struct EventEnvelope 

Source
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: EventId

Globally unique event instance identifier (assigned by store).

§stream_id: StreamId

The stream this event belongs to (e.g. process/xxxxxxxx).

§sequence_number: u64

1-based monotonic position within the stream (assigned by store).

§timestamp: OffsetDateTime

Wall-clock time at which the event was appended to the store (assigned by store).

§correlation_id: CorrelationId

Groups 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: ConversationId

Links events belonging to the same business conversation (e.g. a UTILMD exchange and its APERAK acknowledgement).

§process_id: ProcessId

Stable identifier for the MaKo process instance that owns this stream.

§tenant_id: TenantId

Tenant that owns this event (market participant or deployment tenant).

§workflow_id: WorkflowId

Identifies 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: u32

Schema version of the serialized payload. Increment when the payload structure changes to enable upcasting during replay.

§payload: Value

The domain event payload, serialized as JSON.

Implementations§

Source§

impl EventEnvelope

Source

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.

Source

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.

Source

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

Source

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

Source§

fn clone(&self) -> EventEnvelope

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EventEnvelope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for EventEnvelope

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for EventEnvelope

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more