Class MessageEnvelopeBuilder<T>
Builder for constructing message envelopes with fluent API.
public sealed class MessageEnvelopeBuilder<T> where T : IDispatchMessage
Type Parameters
TThe type of message payload.
- Inheritance
-
MessageEnvelopeBuilder<T>
- Inherited Members
- Extension Methods
Methods
Build()
Builds the message envelope.
public MessageEnvelope Build()
Returns
- MessageEnvelope
The constructed message envelope.
Exceptions
- InvalidOperationException
Thrown when required fields are missing.
WithCallbacks(Func<CancellationToken, Task>, Func<string?, CancellationToken, Task>)
Sets the acknowledgment callbacks.
public MessageEnvelopeBuilder<T> WithCallbacks(Func<CancellationToken, Task> onAcknowledge, Func<string?, CancellationToken, Task> onReject)
Parameters
onAcknowledgeFunc<CancellationToken, Task>The callback function to invoke when the message is acknowledged.
onRejectFunc<string, CancellationToken, Task>The callback function to invoke when the message is rejected, with an optional reason.
Returns
WithContext(IMessageContext)
Sets the message context.
public MessageEnvelopeBuilder<T> WithContext(IMessageContext context)
Parameters
contextIMessageContextThe message context containing metadata.
Returns
WithMessage(T)
Sets the message payload.
public MessageEnvelopeBuilder<T> WithMessage(T message)
Parameters
messageTThe message payload to include in the envelope.
Returns
WithMessageId(string)
Sets the message ID.
public MessageEnvelopeBuilder<T> WithMessageId(string messageId)
Parameters
messageIdstringThe unique identifier for the message.
Returns
WithTimestamp(DateTimeOffset)
Sets the timestamp.
public MessageEnvelopeBuilder<T> WithTimestamp(DateTimeOffset timestamp)
Parameters
timestampDateTimeOffsetThe timestamp when the message was created or sent.