Skip to main content

IntegrationEvent

Trait IntegrationEvent 

Source
pub trait IntegrationEvent:
    Clone
    + Send
    + Sync
    + Serialize
    + for<'de> Deserialize<'de>
    + 'static {
    // Required methods
    fn event_type(&self) -> &'static str;
    fn source_context(&self) -> &'static str;
    fn aggregate_id(&self) -> &str;
    fn occurred_at(&self) -> DateTime<Utc>;

    // Provided methods
    fn version(&self) -> u32 { ... }
    fn correlation_id(&self) -> Option<&str> { ... }
}
Expand description

Trait for integration events that cross bounded context boundaries

Integration events are serializable and contain only primitive/common types to avoid coupling between modules. They follow a naming convention: {source_context}.{aggregate}.{action} (e.g., “sapiens.user.created”)

§Implementation Requirements

  • Must be Clone + Send + Sync + 'static for async handling
  • Must implement Serialize + Deserialize for JSON transport
  • Should only use primitive types (String, numbers, booleans)
  • Event type should follow dot-notation naming

§Example

ⓘ
impl IntegrationEvent for UserCreatedEvent {
    fn event_type(&self) -> &'static str { "sapiens.user.created" }
    fn source_context(&self) -> &'static str { "sapiens" }
    fn aggregate_id(&self) -> &str { &self.user_id }
    fn occurred_at(&self) -> DateTime<Utc> { self.occurred_at }
}

Required Methods§

Source

fn event_type(&self) -> &'static str

Event type identifier using dot notation

Format: {source_context}.{aggregate}.{action} Examples: “sapiens.user.created”, “postman.email.sent”

Source

fn source_context(&self) -> &'static str

Source bounded context that publishes this event

Examples: “sapiens”, “postman”, “bucket”

Source

fn aggregate_id(&self) -> &str

Aggregate ID in the source context

This identifies which aggregate instance the event belongs to

Source

fn occurred_at(&self) -> DateTime<Utc>

When the event occurred in the domain

Provided Methods§

Source

fn version(&self) -> u32

Event schema version for evolution

Increment when making breaking changes to the event structure. Consumers can use this to handle multiple versions.

Source

fn correlation_id(&self) -> Option<&str>

Correlation ID for distributed tracing

Used to trace a request across multiple bounded contexts. Returns None by default; override if your event carries correlation info.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§