In-Memory Transport
The in-memory transport is included with Dispatch and is ideal for testing, development, and single-process scenarios.
Before You Start
- .NET 8.0+ (or .NET 9/10 for latest features)
- Install the required packages:
dotnet add package Excalibur.Dispatch - Familiarity with choosing a transport and dependency injection
Quick Start
builder.Services.AddDispatch(typeof(Program).Assembly);
builder.Services.AddInMemoryTransport("inmemory");
Configuration
builder.Services.AddDispatch(typeof(Program).Assembly);
builder.Services.AddInMemoryTransport("inmemory", options =>
{
// Channel capacity for bounded message queue (default: 1000)
// Producers will wait when capacity is reached
options.ChannelCapacity = 2000;
});
Configuration Options
| Option | Default | Description |
|---|---|---|
ChannelCapacity | 1000 | Maximum messages in the bounded channel. When reached, producers wait for space. |
Testing Scenarios
The in-memory transport provides properties and methods specifically designed for testing:
var registry = serviceProvider.GetRequiredService<TransportRegistry>();
var adapter = (InMemoryTransportAdapter)registry.GetTransportAdapter("inmemory")!;
// Inspect sent messages (keyed by message ID)
IReadOnlyDictionary<string, IDispatchMessage> messages = adapter.SentMessages;
// Clear messages between tests
adapter.ClearSentMessages();
// Check transport state
bool isRunning = adapter.IsRunning;
Add using Excalibur.Dispatch.Transport; to access TransportRegistry and InMemoryTransportAdapter.
Health Checks
The in-memory transport implements ITransportHealthChecker for integration with ASP.NET Core health checks:
services.AddHealthChecks()
.AddTransportHealthChecks();
Health status is determined by:
- Healthy: Transport is running with acceptable failure rate
- Degraded: Running but failure rate exceeds 10%
- Unhealthy: Transport is not running
Limitations
- No persistence — messages are lost on restart
- Single-process only — no network communication
- Not suitable for production distributed scenarios
Next Steps
- Kafka Transport — For production high-throughput scenarios
- RabbitMQ Transport — For production messaging with routing
See Also
- Transports Overview - All available transport providers
- Transport Test Doubles - InMemory test doubles for transport testing
- Choosing a Transport - Comparison guide for transport selection