Table of Contents

Class MessageEnvelopeBuilder<T>

Namespace
Excalibur.Dispatch
Assembly
Excalibur.Dispatch.Abstractions.dll

Builder for constructing message envelopes with fluent API.

public sealed class MessageEnvelopeBuilder<T> where T : IDispatchMessage

Type Parameters

T

The 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

onAcknowledge Func<CancellationToken, Task>

The callback function to invoke when the message is acknowledged.

onReject Func<string, CancellationToken, Task>

The callback function to invoke when the message is rejected, with an optional reason.

Returns

MessageEnvelopeBuilder<T>

WithContext(IMessageContext)

Sets the message context.

public MessageEnvelopeBuilder<T> WithContext(IMessageContext context)

Parameters

context IMessageContext

The message context containing metadata.

Returns

MessageEnvelopeBuilder<T>

WithMessage(T)

Sets the message payload.

public MessageEnvelopeBuilder<T> WithMessage(T message)

Parameters

message T

The message payload to include in the envelope.

Returns

MessageEnvelopeBuilder<T>

WithMessageId(string)

Sets the message ID.

public MessageEnvelopeBuilder<T> WithMessageId(string messageId)

Parameters

messageId string

The unique identifier for the message.

Returns

MessageEnvelopeBuilder<T>

WithTimestamp(DateTimeOffset)

Sets the timestamp.

public MessageEnvelopeBuilder<T> WithTimestamp(DateTimeOffset timestamp)

Parameters

timestamp DateTimeOffset

The timestamp when the message was created or sent.

Returns

MessageEnvelopeBuilder<T>