Skip to main content

IntegrationEventEnvelope

Struct IntegrationEventEnvelope 

Source
pub struct IntegrationEventEnvelope {
    pub id: String,
    pub event_type: String,
    pub source_context: String,
    pub aggregate_id: String,
    pub occurred_at: DateTime<Utc>,
    pub published_at: DateTime<Utc>,
    pub version: u32,
    pub correlation_id: Option<String>,
    pub causation_id: Option<String>,
    pub payload: Value,
}
Expand description

Type-erased integration event envelope for cross-module transport

The envelope wraps any integration event with metadata and serializes the event payload to JSON for transport between bounded contexts.

§Fields

  • id: Unique envelope ID (UUID)
  • event_type: Dot-notation event type
  • source_context: Origin bounded context
  • payload: JSON-serialized event data

§Example

ⓘ
let event = UserCreatedIntegrationEvent { ... };
let envelope = IntegrationEventEnvelope::from_event(&event)?;

// Later, deserialize back to the typed event
let restored: UserCreatedIntegrationEvent = envelope.deserialize()?;

Fields§

§id: String

Unique envelope ID

§event_type: String

Event type (e.g., “sapiens.user.created”)

§source_context: String

Source bounded context

§aggregate_id: String

Aggregate ID in source context

§occurred_at: DateTime<Utc>

When the event occurred

§published_at: DateTime<Utc>

When the envelope was created/published

§version: u32

Event schema version

§correlation_id: Option<String>

Correlation ID for distributed tracing

§causation_id: Option<String>

Causation ID (parent event/envelope that caused this one)

§payload: Value

JSON-serialized event payload

Implementations§

Source§

impl IntegrationEventEnvelope

Source

pub fn from_event<E: IntegrationEvent>(event: &E) -> Result<Self, Error>

Create an envelope from an integration event

Serializes the event to JSON and wraps it with metadata.

§Errors

Returns serde_json::Error if the event cannot be serialized.

Source

pub fn deserialize<E: IntegrationEvent>(&self) -> Result<E, Error>

Deserialize the payload back to a typed event

§Errors

Returns serde_json::Error if the payload doesn’t match the expected type.

Source

pub fn with_causation_id(self, causation_id: impl Into<String>) -> Self

Set the causation ID (for event chaining)

Source

pub fn with_correlation_id(self, correlation_id: impl Into<String>) -> Self

Set the correlation ID (for distributed tracing)

Source

pub fn matches_pattern(&self, pattern: &str) -> bool

Check if this envelope matches a pattern

Patterns support:

  • Exact match: “sapiens.user.created”
  • Wildcard suffix: “sapiens.user.*” matches “sapiens.user.created”, “sapiens.user.deleted”
  • Global wildcard: “*” matches everything

Trait Implementations§

Source§

impl Clone for IntegrationEventEnvelope

Source§

fn clone(&self) -> Self

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 IntegrationEventEnvelope

Source§

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

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

impl<'de> Deserialize<'de> for IntegrationEventEnvelope

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 IntegrationEventEnvelope

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<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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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<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