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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//! Backbone Messaging - Event-driven messaging infrastructure
//!
//! This crate provides a generic, type-safe event bus system for domain events
//! following the Event-Driven Architecture and CQRS patterns.
//!
//! # Features
//!
//! - **Generic Event Bus**: Type-safe publish/subscribe for any event type
//! - **Event Envelope**: Metadata wrapper with correlation/causation IDs
//! - **Event Handlers**: Async trait-based event handling
//! - **Event History**: Optional event persistence for replay
//! - **Composite Events**: Support for aggregate event streams
//! - **Integration Events**: Cross-bounded context communication (Phase 6)
//!
//! # Domain Events vs Integration Events
//!
//! | Aspect | Domain Event | Integration Event |
//! |--------|--------------|-------------------|
//! | Scope | Single bounded context | Cross-context |
//! | Types | Can use domain types | Primitives only (JSON) |
//! | Coupling | Internal | Loose coupling |
//! | Bus | `EventBus<E>` (typed) | `IntegrationEventBus` (type-erased) |
//!
//! # Example - Domain Events
//!
//! ```rust,ignore
//! use backbone_messaging::{EventBus, EventHandler, DomainEvent};
//! use async_trait::async_trait;
//!
//! // Define your domain event
//! #[derive(Clone, Debug)]
//! struct UserCreated {
//! user_id: String,
//! email: String,
//! }
//!
//! impl DomainEvent for UserCreated {
//! fn event_type(&self) -> &'static str { "UserCreated" }
//! fn aggregate_id(&self) -> &str { &self.user_id }
//! }
//!
//! // Create and use the event bus
//! let bus = EventBus::<UserCreated>::new();
//! bus.publish(UserCreated { user_id: "123".into(), email: "test@example.com".into() }).await?;
//! ```
//!
//! # Example - Integration Events (Cross-Module)
//!
//! ```rust,ignore
//! use backbone_messaging::{IntegrationEventBus, IntegrationEvent, IntegrationEventHandler};
//! use chrono::{DateTime, Utc};
//! use serde::{Deserialize, Serialize};
//!
//! // Define an integration event (must be serializable)
//! #[derive(Clone, Debug, Serialize, Deserialize)]
//! struct UserCreatedIntegrationEvent {
//! user_id: String,
//! email: String,
//! occurred_at: DateTime<Utc>,
//! }
//!
//! impl IntegrationEvent for UserCreatedIntegrationEvent {
//! 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 }
//! }
//!
//! // Publish from Sapiens module
//! let bus = IntegrationEventBus::new();
//! bus.publish(UserCreatedIntegrationEvent { ... }).await?;
//!
//! // Subscribe in Postman module (using wildcard pattern)
//! bus.register_handler(Arc::new(EmailHandler)).await; // patterns: ["sapiens.user.*"]
//! ```
// Domain Events (internal to bounded context)
// Integration Events (cross-bounded context)
// Generic CRUD event infrastructure (Phase 0)
// Domain Event exports
pub use DomainEvent;
pub use ;
pub use ;
pub use EventError;
pub use ;
// Integration Event exports
pub use ;
pub use ;
// Generic CRUD event re-exports
pub use ;
pub use ;
pub use ;
/// Prelude module for convenient imports