Class MessageMetadata
Default implementation of the unified message metadata interface.
[JsonConverter(typeof(MessageMetadataJsonConverter))]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.PublicProperties)]
public sealed record MessageMetadata : IMessageMetadata, IEquatable<MessageMetadata>
- Inheritance
-
MessageMetadata
- Implements
- Inherited Members
- Extension Methods
Remarks
This class provides an immutable, thread-safe implementation of message metadata that consolidates all metadata requirements across the Excalibur framework. Use the builder pattern via ToBuilder() or MessageMetadataBuilder to create or modify instances.
The core dispatch identity fields remain on the root to satisfy the IMessageMetadata contract. All other metadata is composed into focused, each-at-most-ten-property value types (MessageIdentity, MessageRouting, MessageTiming, MessageObservability, MessageDelivery, MessageEventSourcing, MessageSecurity) following the Microsoft-first sub-option composition pattern. When accessed through the IMessageMetadata interface, non-core values are also available via extension methods that read from the Properties dictionary.
The wire (JSON) shape is preserved as a flat object via MessageMetadataJsonConverter so composing the groups does not change serialization output for consumers.
Constructors
MessageMetadata()
Initializes a new instance of the MessageMetadata class.
public MessageMetadata()
Properties
CausationId
Gets the causation identifier that tracks what caused this message to be created.
public string? CausationId { get; init; }
Property Value
- string
The current CausationId value.
ContentType
Gets the MIME type of the message content.
public required string ContentType { get; init; }
Property Value
- string
The current ContentType value.
CorrelationId
Gets the correlation identifier for tracking related messages.
public required string CorrelationId { get; init; }
Property Value
- string
The current CorrelationId value.
CreatedTimestampUtc
Gets the UTC timestamp when the message was created.
public required DateTimeOffset CreatedTimestampUtc { get; init; }
Property Value
- DateTimeOffset
The current CreatedTimestampUtc value.
Delivery
Gets the delivery and transport-reliability metadata group.
public MessageDelivery Delivery { get; init; }
Property Value
- MessageDelivery
The current Delivery value.
EventSourcing
Gets the event-sourcing metadata group.
public MessageEventSourcing EventSourcing { get; init; }
Property Value
- MessageEventSourcing
The current EventSourcing value.
Headers
Gets the dictionary of message headers.
public IReadOnlyDictionary<string, string> Headers { get; init; }
Property Value
- IReadOnlyDictionary<string, string>
The current Headers value.
Identity
Gets the supplemental identity and versioning metadata group.
public MessageIdentity Identity { get; init; }
Property Value
- MessageIdentity
The current Identity value.
MessageId
Gets the unique identifier for this message.
public required string MessageId { get; init; }
Property Value
MessageType
Gets the type identifier for the message.
public required string MessageType { get; init; }
Property Value
- string
The current MessageType value.
Observability
Gets the distributed-tracing observability metadata group.
public MessageObservability Observability { get; init; }
Property Value
- MessageObservability
The current Observability value.
Properties
Gets the dictionary of message properties, including moved metadata fields.
public IReadOnlyDictionary<string, object> Properties { get; init; }
Property Value
- IReadOnlyDictionary<string, object>
The current Properties value.
Routing
Gets the routing and addressing metadata group.
public MessageRouting Routing { get; init; }
Property Value
- MessageRouting
The current Routing value.
Security
Gets the security and tenancy metadata group.
public MessageSecurity Security { get; init; }
Property Value
- MessageSecurity
The current Security value.
Source
Gets the source of the message.
public string? Source { get; init; }
Property Value
Timing
Gets the temporal metadata group.
public MessageTiming Timing { get; init; }
Property Value
- MessageTiming
The current Timing value.
Methods
CloneMetadata()
Creates a deep copy of this metadata instance.
public IMessageMetadata CloneMetadata()
Returns
- IMessageMetadata
A new instance with the same values as this instance.
CreateDefault()
Creates a new metadata instance with default values.
public static MessageMetadata CreateDefault()
Returns
- MessageMetadata
A new MessageMetadata instance with default values.
FromLegacyMetadata(IMessageMetadata, IMessageContext?)
Creates a new metadata instance from an existing IMessageMetadata.
public static MessageMetadata FromLegacyMetadata(IMessageMetadata legacy, IMessageContext? context = null)
Parameters
legacyIMessageMetadataThe legacy metadata to convert.
contextIMessageContextOptional message context for additional metadata.
Returns
- MessageMetadata
A new MessageMetadata instance converted from the legacy metadata.
Exceptions
- ArgumentNullException
Thrown when legacy is null.
GetValidationErrors()
Gets validation errors if the metadata is invalid.
public IReadOnlyCollection<string> GetValidationErrors()
Returns
- IReadOnlyCollection<string>
A collection of validation error messages, or empty if valid.
ToBuilder()
Creates a mutable builder from this metadata instance.
public IMessageMetadataBuilder ToBuilder()
Returns
- IMessageMetadataBuilder
A builder that can be used to create a modified copy of this metadata.
Validate()
Validates that all required fields are present and valid.
public bool Validate()
Returns
- bool
True if the metadata is valid; otherwise, false.