Metadata¶
_metadata
¶
MessageMetadata value object for messaging patterns.
MessageMetadata
¶
Bases: ValueObject[dict[str, object]]
Metadata associated with foundational messages.
Contains technical-level information about messages such as:
- Unique message identifier
- When the message was created
- correlation_id is used to trace related messages across systems
and link messages that belong to the same business process.
- causation_id is used to identify the immediate predecessor message that caused
this message.
This separation allows messages to focus on foundational data while keeping
infrastructure handling concerns in metadata without needing to understand anything about
infrastructure rules.
Example
Source code in src/forging_blocks/domain/messages/message/_metadata.py
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 | |
message_id: UUID
property
¶
Get the unique identifier for this message.
Returns:
| Type | Description |
|---|---|
UUID
|
The unique message identifier. |
causation_id: UUID
property
¶
Get the causation ID for this message.
Returns:
| Type | Description |
|---|---|
UUID
|
The causation identifier. |
created_at: datetime
property
¶
Get the timestamp when this message was created.
Returns:
| Type | Description |
|---|---|
datetime
|
The timestamp (preserved as given when provided, or the |
datetime
|
current UTC time when defaulted). |
correlation_id: UUID
property
¶
Get the correlation ID for this message.
Returns:
| Type | Description |
|---|---|
UUID
|
The correlation identifier. |
message_type: str
property
¶
Get the type of this message.
Returns:
| Type | Description |
|---|---|
str
|
The message type name. |
value: dict[str, object]
property
¶
Get the raw dictionary representation of the metadata.
__init__(message_type: str, message_id: UUID | None = None, created_at: datetime | None = None, correlation_id: UUID | None = None, causation_id: UUID | None = None) -> None
¶
Initialize message metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_type
|
str
|
The type/name of the message. |
required |
message_id
|
UUID | None
|
Unique identifier for the message. If None, generates a |
None
|
created_at
|
datetime | None
|
When the message was created. If None, uses current UTC time. |
None
|
correlation_id
|
UUID | None
|
Identifier to correlate related messages. If None, |
None
|
causation_id
|
UUID | None
|
Identifier of the message that caused this one. If None, |
None
|