29
29
PROP_PARTITION_KEY ,
30
30
PROP_PARTITION_KEY_AMQP_SYMBOL ,
31
31
PROP_TIMESTAMP ,
32
+ PROP_ABSOLUTE_EXPIRY_TIME ,
33
+ PROP_CONTENT_ENCODING ,
34
+ PROP_CONTENT_TYPE ,
35
+ PROP_CORRELATION_ID ,
36
+ PROP_GROUP_ID ,
37
+ PROP_GROUP_SEQUENCE ,
38
+ PROP_MESSAGE_ID ,
39
+ PROP_REPLY_TO ,
40
+ PROP_REPLY_TO_GROUP_ID ,
41
+ PROP_SUBJECT ,
42
+ PROP_TO ,
43
+ PROP_USER_ID ,
44
+ PROP_CREATION_TIME ,
32
45
)
33
46
34
47
if TYPE_CHECKING :
39
52
# event_data.encoded_size < 255, batch encode overhead is 5, >=256, overhead is 8 each
40
53
_BATCH_MESSAGE_OVERHEAD_COST = [5 , 8 ]
41
54
55
+ _SYS_PROP_KEYS_TO_MSG_PROPERTIES = (
56
+ (PROP_MESSAGE_ID , "message_id" ),
57
+ (PROP_USER_ID , "user_id" ),
58
+ (PROP_TO , "to" ),
59
+ (PROP_SUBJECT , "subject" ),
60
+ (PROP_REPLY_TO , "reply_to" ),
61
+ (PROP_CORRELATION_ID , "correlation_id" ),
62
+ (PROP_CONTENT_TYPE , "content_type" ),
63
+ (PROP_CONTENT_ENCODING , "content_encoding" ),
64
+ (PROP_ABSOLUTE_EXPIRY_TIME , "absolute_expiry_time" ),
65
+ (PROP_CREATION_TIME , "creation_time" ),
66
+ (PROP_GROUP_ID , "group_id" ),
67
+ (PROP_GROUP_SEQUENCE , "group_sequence" ),
68
+ (PROP_REPLY_TO_GROUP_ID , "reply_to_group_id" ),
69
+ )
70
+
42
71
43
72
class EventData (object ):
44
73
"""The EventData class is a container for event content.
@@ -60,6 +89,7 @@ class EventData(object):
60
89
def __init__ (self , body = None ):
61
90
# type: (Union[str, bytes, List[AnyStr]]) -> None
62
91
self ._last_enqueued_event_properties = {} # type: Dict[str, Any]
92
+ self ._sys_properties = None # type: Optional[Dict[bytes, Any]]
63
93
if body and isinstance (body , list ):
64
94
self .message = Message (body [0 ])
65
95
for more in body [1 :]:
@@ -207,12 +237,42 @@ def properties(self, value):
207
237
208
238
@property
209
239
def system_properties (self ):
210
- # type: () -> Dict[Union[str, bytes], Any]
211
- """Metadata set by the Event Hubs Service associated with the event
240
+ # type: () -> Dict[bytes, Any]
241
+ """Metadata set by the Event Hubs Service associated with the event.
242
+
243
+ An EventData could have some or all of the following meta data depending on the source
244
+ of the event data.
245
+
246
+ - b"x-opt-sequence-number" (int)
247
+ - b"x-opt-offset" (bytes)
248
+ - b"x-opt-partition-key" (bytes)
249
+ - b"x-opt-enqueued-time" (int)
250
+ - b"message-id" (bytes)
251
+ - b"user-id" (bytes)
252
+ - b"to" (bytes)
253
+ - b"subject" (bytes)
254
+ - b"reply-to" (bytes)
255
+ - b"correlation-id" (bytes)
256
+ - b"content-type" (bytes)
257
+ - b"content-encoding" (bytes)
258
+ - b"absolute-expiry-time" (int)
259
+ - b"creation-time" (int)
260
+ - b"group-id" (bytes)
261
+ - b"group-sequence" (bytes)
262
+ - b"reply-to-group-id" (bytes)
212
263
213
264
:rtype: dict
214
265
"""
215
- return self .message .annotations
266
+
267
+ if self ._sys_properties is None :
268
+ self ._sys_properties = {}
269
+ if self .message .properties :
270
+ for key , prop_name in _SYS_PROP_KEYS_TO_MSG_PROPERTIES :
271
+ value = getattr (self .message .properties , prop_name , None )
272
+ if value :
273
+ self ._sys_properties [key ] = value
274
+ self ._sys_properties .update (self .message .annotations )
275
+ return self ._sys_properties
216
276
217
277
@property
218
278
def body (self ):
0 commit comments