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 + 'staticfor async handling - Must implement
Serialize + Deserializefor 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§
Sourcefn event_type(&self) -> &'static str
fn event_type(&self) -> &'static str
Event type identifier using dot notation
Format: {source_context}.{aggregate}.{action}
Examples: “sapiens.user.created”, “postman.email.sent”
Sourcefn source_context(&self) -> &'static str
fn source_context(&self) -> &'static str
Source bounded context that publishes this event
Examples: “sapiens”, “postman”, “bucket”
Sourcefn aggregate_id(&self) -> &str
fn aggregate_id(&self) -> &str
Aggregate ID in the source context
This identifies which aggregate instance the event belongs to
Sourcefn occurred_at(&self) -> DateTime<Utc>
fn occurred_at(&self) -> DateTime<Utc>
When the event occurred in the domain
Provided Methods§
Sourcefn version(&self) -> u32
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.
Sourcefn correlation_id(&self) -> Option<&str>
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".