Interface ITransportMessageContext
Provides transport-level context for messages being transformed between different message transports.
public interface ITransportMessageContext
- Extension Methods
Remarks
This interface captures the transport-agnostic metadata required for multi-transport message mapping. It differs from IMessageContext which is focused on the dispatch pipeline. ITransportMessageContext is specifically designed for:
- Capturing source transport metadata when receiving messages
- Configuring target transport properties when publishing messages
- Enabling message transformation between transport formats (RabbitMQ ↔ Kafka ↔ SQS)
- Preserving correlation and tracing information across transport boundaries
Transport-specific implementations (e.g., RabbitMqMessageContext, KafkaMessageContext)
extend this interface with transport-specific properties accessible via GetTransportProperty<T>(string).
Properties
CausationId
Gets the causation identifier linking this message to its direct cause.
string? CausationId { get; }
Property Value
ContentType
Gets the content type of the message payload.
string? ContentType { get; }
Property Value
CorrelationId
Gets the correlation identifier for tracking related messages across services.
string? CorrelationId { get; }
Property Value
Headers
Gets the message headers as key-value pairs.
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.
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.
string? SourceTransport { get; }
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.
string? TargetTransport { get; }
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.
string? TenantId { get; }
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.
DateTimeOffset Timestamp { get; }
Property Value
- DateTimeOffset
The message timestamp in UTC.
Methods
GetAllTransportProperties()
Gets all transport-specific properties as a dictionary.
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.
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.
bool HasTransportProperty(string propertyName)
Parameters
propertyNamestringThe name of the property to check.
Returns
SetTransportProperty<T>(string, T)
Sets a transport-specific property by name.
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.