Class TransportMessageContext
Base implementation of ITransportMessageContext providing transport-agnostic message context.
public class TransportMessageContext : ITransportMessageContext
- Inheritance
-
TransportMessageContext
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
This class provides a default implementation for the transport message context interface. Transport-specific implementations can extend this class to add transport-specific properties and behavior while inheriting the common functionality.
Constructors
TransportMessageContext()
Initializes a new instance of the TransportMessageContext class with a generated message ID.
public TransportMessageContext()
TransportMessageContext(string)
Initializes a new instance of the TransportMessageContext class.
public TransportMessageContext(string messageId)
Parameters
messageIdstringThe unique message identifier.
Properties
CausationId
Gets the causation identifier linking this message to its direct cause.
public string? CausationId { get; set; }
Property Value
ContentType
Gets the content type of the message payload.
public string? ContentType { get; set; }
Property Value
CorrelationId
Gets the correlation identifier for tracking related messages across services.
public string? CorrelationId { get; set; }
Property Value
Headers
Gets the message headers as key-value pairs.
public IReadOnlyDictionary<string, string> Headers { get; }
Property Value
- IReadOnlyDictionary<string, string>
A read-only dictionary of header names to header values. Headers provide metadata that travels with the message across transports.
MessageId
Gets the unique identifier for this message.
public string MessageId { get; }
Property Value
- string
The message identifier, typically a GUID string.
SourceTransport
Gets the name of the source transport that originated this message.
public string? SourceTransport { get; set; }
Property Value
- string
The transport name (e.g., "rabbitmq", "kafka", "sqs"), or null if the message did not originate from a transport.
TargetTransport
Gets the name of the target transport for message delivery.
public string? TargetTransport { get; set; }
Property Value
- string
The transport name (e.g., "rabbitmq", "kafka", "sqs"), or null if no specific target is configured.
TenantId
Gets the tenant identifier that scopes this message to a single tenant.
public string? TenantId { get; set; }
Property Value
Remarks
Tenancy is an isolation invariant: it is modeled as a first-class field (not a loose header) so
every transport mapper copies it explicitly, mirroring CorrelationId. Relying on the
untyped Headers bag risks silently dropping the tenant on any mapper that rebuilds
context, which can cause cross-tenant misdelivery. The standard wire header key is
OutboxHeaderNames.TenantId ("tenant-id").
Timestamp
Gets the timestamp when the message was created or sent.
public DateTimeOffset Timestamp { get; set; }
Property Value
- DateTimeOffset
The message timestamp in UTC.
Methods
GetAllTransportProperties()
Gets all transport-specific properties as a dictionary.
public IReadOnlyDictionary<string, object?> GetAllTransportProperties()
Returns
- IReadOnlyDictionary<string, object>
A read-only dictionary of all transport-specific property names and values.
GetTransportProperty<T>(string)
Gets a transport-specific property by name.
public T? GetTransportProperty<T>(string propertyName)
Parameters
propertyNamestringThe name of the transport-specific property.
Returns
- T
The property value cast to
T, or default if the property is not found or cannot be cast.
Type Parameters
TThe expected type of the property value.
Examples
// RabbitMQ-specific property
var routingKey = context.GetTransportProperty<string>("RoutingKey");
// Kafka-specific property
var partition = context.GetTransportProperty<int>("Partition");
Remarks
Use this method to access transport-specific properties that are not part of the common interface. Examples include:
- RabbitMQ: RoutingKey, Exchange, DeliveryTag
- Kafka: Partition, Offset, Key
- SQS: ReceiptHandle, MessageGroupId, SequenceNumber
HasTransportProperty(string)
Determines whether a transport-specific property exists.
public bool HasTransportProperty(string propertyName)
Parameters
propertyNamestringThe name of the property to check.
Returns
RemoveHeader(string)
Removes a header by name.
public bool RemoveHeader(string name)
Parameters
namestringThe header name to remove.
Returns
SetHeader(string, string)
Sets a header value.
public void SetHeader(string name, string value)
Parameters
SetHeaders(IEnumerable<KeyValuePair<string, string>>)
Sets multiple headers at once.
public void SetHeaders(IEnumerable<KeyValuePair<string, string>> headers)
Parameters
headersIEnumerable<KeyValuePair<string, string>>The headers to set.
SetTransportProperty<T>(string, T)
Sets a transport-specific property by name.
public void SetTransportProperty<T>(string propertyName, T value)
Parameters
propertyNamestringThe name of the transport-specific property.
valueTThe property value to set.
Type Parameters
TThe type of the property value.
Remarks
Use this method to set transport-specific properties when preparing a message for delivery to a specific transport. The properties set here will be used by the target transport adapter.