Class InMemoryTransportAdapter
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
loggerILogger<InMemoryTransportAdapter>The logger instance.
optionsInMemoryTransportOptionsThe adapter options.
Fields
DefaultName
The default transport name for in-memory adapters.
public const string DefaultName = "InMemory"
Field Value
TransportTypeName
The transport type identifier.
public const string TransportTypeName = "inmemory"
Field Value
Properties
IsRunning
Gets a value indicating whether the adapter is currently running.
public bool IsRunning { get; }
Property Value
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
contextTransportHealthCheckContextThe health check context.
cancellationTokenCancellationTokenCancellation 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
cancellationTokenCancellationTokenCancellation 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
cancellationTokenCancellationToken
Returns
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
transportMessageobjectThe raw transport message.
dispatcherIDispatcherThe dispatcher to route through.
cancellationTokenCancellationTokenCancellation 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
messageIDispatchMessageThe message to send.
destinationstringThe destination endpoint.
contextIMessageContextThe message context containing correlation, tenant, and other propagation data.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
Task representing the send operation.
StartAsync(CancellationToken)
Starts the transport adapter.
public Task StartAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationToken
Returns
StopAsync(CancellationToken)
Stops the transport adapter.
public Task StopAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationToken