@@ -49,6 +49,11 @@ pub trait Event: EventInfo {
49
49
50
50
/// The class/type of the event. This is used to group/categorize events together.
51
51
fn class ( & self ) -> Self :: EventType ;
52
+
53
+ /// Metadata associated with the event
54
+ fn metadata ( & self ) -> HashMap < String , String > {
55
+ HashMap :: new ( )
56
+ }
52
57
}
53
58
54
59
/// Hold the context information for any events
73
78
event : E ,
74
79
}
75
80
76
- struct RawEvent < T , A : Event < EventType = T > > ( HashMap < String , Value > , A ) ;
81
+ /// A flattened event that flattens the context provided to it along with the actual event.
82
+ struct FlatMapEvent < T , A : Event < EventType = T > > ( HashMap < String , Value > , A ) ;
77
83
78
84
impl < T , A , E , D > EventBuilder < T , A , E , D >
79
85
where
@@ -109,12 +115,13 @@ where
109
115
/// Emit the event.
110
116
pub fn try_emit ( self ) -> Result < ( ) , EventsError > {
111
117
let ts = self . event . timestamp ( ) ;
118
+ let metadata = self . event . metadata ( ) ;
112
119
self . message_sink
113
- . send_message ( RawEvent ( self . metadata , self . event ) , ts)
120
+ . send_message ( FlatMapEvent ( self . metadata , self . event ) , metadata , ts)
114
121
}
115
122
}
116
123
117
- impl < T , A > Serialize for RawEvent < T , A >
124
+ impl < T , A > Serialize for FlatMapEvent < T , A >
118
125
where
119
126
A : Event < EventType = T > ,
120
127
{
@@ -236,7 +243,12 @@ pub trait MessagingInterface {
236
243
/// The type of the event used for categorization by the event publisher.
237
244
type MessageClass ;
238
245
/// Send a message that follows the defined message class.
239
- fn send_message < T > ( & self , data : T , timestamp : PrimitiveDateTime ) -> Result < ( ) , EventsError >
246
+ fn send_message < T > (
247
+ & self ,
248
+ data : T ,
249
+ metadata : HashMap < String , String > ,
250
+ timestamp : PrimitiveDateTime ,
251
+ ) -> Result < ( ) , EventsError >
240
252
where
241
253
T : Message < Class = Self :: MessageClass > + ErasedMaskSerialize ;
242
254
}
@@ -252,7 +264,7 @@ pub trait Message {
252
264
fn identifier ( & self ) -> String ;
253
265
}
254
266
255
- impl < T , A > Message for RawEvent < T , A >
267
+ impl < T , A > Message for FlatMapEvent < T , A >
256
268
where
257
269
A : Event < EventType = T > ,
258
270
{
0 commit comments