Table of Contents

Class MemoryMessage

Namespace
Excalibur.Dispatch.Messaging
Assembly
Excalibur.Dispatch.dll

A message implementation that holds its content as Memory<byte> for zero-copy operations.

public sealed class MemoryMessage : IMemoryMessage, IDispatchMessage, IDisposable
Inheritance
MemoryMessage
Implements
Inherited Members
Extension Methods

Constructors

MemoryMessage(IMemoryOwner<byte>, int, string)

Initializes a new instance of the MemoryMessage class with owned memory and explicit payload length.

public MemoryMessage(IMemoryOwner<byte> memoryOwner, int payloadLength, string contentType = "application/octet-stream")

Parameters

memoryOwner IMemoryOwner<byte>

The memory owner that manages the message body.

payloadLength int

The valid payload length within memoryOwner memory.

contentType string

The content type of the message body.

MemoryMessage(IMemoryOwner<byte>, string)

Initializes a new instance of the MemoryMessage class with owned memory.

public MemoryMessage(IMemoryOwner<byte> memoryOwner, string contentType = "application/octet-stream")

Parameters

memoryOwner IMemoryOwner<byte>

The memory owner that manages the message body.

contentType string

The content type of the message body.

MemoryMessage(Memory<byte>, string)

Initializes a new instance of the MemoryMessage class with borrowed memory.

public MemoryMessage(Memory<byte> body, string contentType)

Parameters

body Memory<byte>

The message body as borrowed memory.

contentType string

The content type of the message body.

Properties

Body

Gets the message body as a Memory<byte>.

public Memory<byte> Body { get; }

Property Value

Memory<byte>

The memory-backed payload for the message.

Remarks

This property enables zero-copy message processing by allowing messages to reference memory directly without copying data. The memory should remain valid for the lifetime of the message processing.

ContentType

Gets the content type of the message body.

public string ContentType { get; }

Property Value

string

The MIME content type of the payload.

Remarks

Common values include "application/json", "application/octet-stream", "text/plain", etc. This helps consumers understand how to interpret the Body data.

Features

public IMessageFeatures Features { get; }

Property Value

IMessageFeatures

Headers

public IReadOnlyDictionary<string, object> Headers { get; }

Property Value

IReadOnlyDictionary<string, object>

Id

public Guid Id { get; }

Property Value

Guid

MessageId

public string MessageId { get; }

Property Value

string

MessageType

public string MessageType { get; }

Property Value

string

OwnsMemory

Gets a value indicating whether the body memory is owned by this message.

public bool OwnsMemory { get; }

Property Value

bool

true if the message owns the underlying memory; otherwise, false.

Remarks

When true, the message is responsible for managing the lifetime of the memory. When false, the memory is borrowed and should not be disposed by the message.

Timestamp

public DateTimeOffset Timestamp { get; }

Property Value

DateTimeOffset

Methods

Dispose()

Disposes the message and returns any owned memory to the pool.

public void Dispose()