Table of Contents

Class InMemoryTransportAdapter

Namespace
Excalibur.Dispatch.Transport
Assembly
Excalibur.Dispatch.dll

In-memory transport adapter for testing and development scenarios.

public sealed class InMemoryTransportAdapter : ITransportAdapter, ITransportAdapterLifecycle, ITransportHealthChecker, ITransportHealthMetrics, IAsyncDisposable
Inheritance
InMemoryTransportAdapter
Implements
Inherited Members
Extension Methods

Remarks

This adapter provides a simple in-memory message transport that can be used for unit testing, local development, and scenarios where external message brokers are not available.

Messages are processed asynchronously through a bounded channel with configurable capacity.

Implements ITransportHealthChecker for integration with ASP.NET Core health checks and the Excalibur.Dispatch.Transport.MultiTransportHealthCheck.

Constructors

InMemoryTransportAdapter(ILogger<InMemoryTransportAdapter>, InMemoryTransportOptions?)

Initializes a new instance of the InMemoryTransportAdapter class.

public InMemoryTransportAdapter(ILogger<InMemoryTransportAdapter> logger, InMemoryTransportOptions? options = null)

Parameters

logger ILogger<InMemoryTransportAdapter>

The logger instance.

options InMemoryTransportOptions

The adapter options.

Fields

DefaultName

The default transport name for in-memory adapters.

public const string DefaultName = "InMemory"

Field Value

string

TransportTypeName

The transport type identifier.

public const string TransportTypeName = "inmemory"

Field Value

string

Properties

IsRunning

Gets a value indicating whether the adapter is currently running.

public bool IsRunning { get; }

Property Value

bool

true if the adapter is running; otherwise, false.

Name

Gets the unique name of this transport adapter.

public string Name { get; }

Property Value

string

The adapter identifier.

SentMessages

Gets the collection of messages that have been sent through this adapter.

public IReadOnlyDictionary<string, IDispatchMessage> SentMessages { get; }

Property Value

IReadOnlyDictionary<string, IDispatchMessage>

A read-only dictionary of sent messages indexed by message ID.

Remarks

This property is useful for testing scenarios where you need to verify that messages were sent correctly.

TransportType

Gets the transport type this adapter handles.

public string TransportType { get; }

Property Value

string

The transport type managed by the adapter.

Methods

CheckHealthAsync(TransportHealthCheckContext, CancellationToken)

Performs a health check operation.

public Task<TransportHealthCheckResult> CheckHealthAsync(TransportHealthCheckContext context, CancellationToken cancellationToken)

Parameters

context TransportHealthCheckContext

The health check context.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<TransportHealthCheckResult>

The health check result.

CheckQuickHealthAsync(CancellationToken)

Performs a quick health check operation (lighter than full check).

public Task<TransportHealthCheckResult> CheckQuickHealthAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Cancellation token.

Returns

Task<TransportHealthCheckResult>

The health check result.

ClearSentMessages()

Clears all sent messages from the internal collection.

public void ClearSentMessages()

Remarks

This method is useful for resetting state between tests.

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

GetHealthMetricsAsync(CancellationToken)

Gets health metrics for this transport.

public Task<TransportHealthMetrics> GetHealthMetricsAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task<TransportHealthMetrics>

ReceiveAsync(object, IDispatcher, CancellationToken)

Receives a message from the transport and routes it through the dispatcher.

public Task<IMessageResult> ReceiveAsync(object transportMessage, IDispatcher dispatcher, CancellationToken cancellationToken)

Parameters

transportMessage object

The raw transport message.

dispatcher IDispatcher

The dispatcher to route through.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<IMessageResult>

The result of message processing.

SendAsync(IDispatchMessage, string, IMessageContext, CancellationToken)

Sends a message through the transport after processing.

public Task SendAsync(IDispatchMessage message, string destination, IMessageContext context, CancellationToken cancellationToken)

Parameters

message IDispatchMessage

The message to send.

destination string

The destination endpoint.

context IMessageContext

The message context containing correlation, tenant, and other propagation data.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Task representing the send operation.

StartAsync(CancellationToken)

Starts the transport adapter.

public Task StartAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task

StopAsync(CancellationToken)

Stops the transport adapter.

public Task StopAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task