1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! CloudEvents v1.0-compliant event ports for hexagonal architecture.
//!
//! This module provides CloudEvents v1.0 specification-compliant ports for
//! transport-agnostic, standardized domain event publishing and consumption.
//! The design integrates seamlessly with hexser's existing DomainEvent trait
//! while providing CloudEvents-standard envelope, ports, and routing.
//!
//! # Architecture
//!
//! - **CloudEventsEnvelope<T>**: CloudEvents v1.0-compliant wrapper struct
//! - **EventPublisher<T>**: Port for publishing events to transports
//! - **EventSubscriber<T>**: Port for consuming events from transports
//! - **EventCodec<T>**: Port for serialization/deserialization
//! - **EventRouter**: Port for topic/subject resolution
//!
//! # CloudEvents v1.0 Compliance
//!
//! All types and traits adhere to the CloudEvents v1.0 specification:
//! - REQUIRED attributes: id, source, specversion, type
//! - OPTIONAL attributes: datacontenttype, dataschema, subject, time, data
//! - Extension attributes support
//! - Transport bindings: HTTP, Kafka, AMQP
//! - JSON format support (application/cloudevents+json)
//!
//! # Integration with DomainEvent
//!
//! The CloudEventsEnvelope wraps domain events implementing the DomainEvent trait:
//! - `event_type()` maps to CloudEvents `type` attribute
//! - `aggregate_id()` maps to CloudEvents `subject` attribute
//! - Domain event becomes the `data` attribute
//!
//! # Examples
//!
//! ```rust
//! // Define a domain event
//! struct UserCreated {
//! user_id: std::string::String,
//! email: std::string::String,
//! }
//!
//! impl hexser::domain::DomainEvent for UserCreated {
//! fn event_type(&self) -> &str {
//! "com.example.user.created"
//! }
//!
//! fn aggregate_id(&self) -> std::string::String {
//! self.user_id.clone()
//! }
//! }
//!
//! // Wrap in CloudEvents envelope
//! let event = UserCreated {
//! user_id: std::string::String::from("user-123"),
//! email: std::string::String::from("user@example.com"),
//! };
//!
//! let envelope = hexser::ports::events::CloudEventsEnvelope::from_domain_event(
//! std::string::String::from("evt-001"),
//! std::string::String::from("/services/user-service"),
//! event,
//! );
//!
//! // Validate CloudEvents compliance
//! envelope.validate().unwrap();
//! envelope.validate_time_format().unwrap();
//!
//! // Publish using EventPublisher port
//! // publisher.publish(&envelope)?;
//! ```
//!
//! Revision History
//! - 2025-10-09T14:51:00Z @AI: Initial events module with CloudEvents v1.0 ports.
// Re-export main types and traits
pub use ;
pub use EventCodec;
pub use EventPublisher;
pub use EventRouter;
pub use EventSubscriber;