-
Notifications
You must be signed in to change notification settings - Fork 16
MemoryTransport
The Memory transport stores messages in-process using concurrent collections. No external dependencies needed. Good for testing, prototyping, and single-process scenarios.
It supports the following features:
- History tracking (opt-in, the only configurable feature)
- Job scheduler
Queues don't need to be created before usage; storage is allocated on demand.
- All data is lost when the application exits
- Producers and consumers must be in the same process
- No heartbeat, message expiration, priority, or status tracking
- No message rollback on failure
The init class is MemoryMessageQueueInit, included in the core DotNetWorkQueue NuGet package. No separate transport NuGet package is needed.
[Producer]
var queueConnection = new QueueConnection(queueName, connectionString);
using (var queueContainer = new QueueContainer<MemoryMessageQueueInit>())
{
using (var queue = queueContainer.CreateProducer<SimpleMessage>(queueConnection))
{
queue.Send(new SimpleMessage { Message = "Hello World" });
}
}[Consumer]
var queueConnection = new QueueConnection(queueName, connectionString);
using (var queueContainer = new QueueContainer<MemoryMessageQueueInit>())
{
using (var queue = queueContainer.CreateConsumer(queueConnection))
{
var notifications = new ConsumerQueueNotifications(
(n) => Console.WriteLine($"Error: {n.Error}"),
(n) => Console.WriteLine($"Receive error: {n.Error}"),
(n) => Console.WriteLine($"Moved to error queue: {n.MessageId}"),
(n) => Console.WriteLine($"Poison message: {n.MessageId}"),
(n) => Console.WriteLine($"Rollback: {n.MessageId}"),
(n) => Console.WriteLine($"Completed: {n.MessageId}"));
queue.Start<SimpleMessage>(HandleMessages, notifications);
Console.WriteLine("Processing messages - press any key to stop");
Console.ReadKey(true);
}
}
private void HandleMessages(IReceivedMessage<SimpleMessage> message, IWorkerNotification notifications)
{
notifications.Log.LogDebug($"Processing Message {message.Body.Message}");
}For more consumer patterns, see ConsumerMethod and ConsumerAsync.
The Memory transport has only one configurable option:
| Property | Type | Default | Notes |
|---|---|---|---|
EnableHistory |
bool |
false |
The only settable feature flag |
All other features (EnablePriority, EnableStatus, EnableHeartBeat, EnableDelayedProcessing, EnableStatusTable, EnableRoute, EnableMessageExpiration) are permanently false.
When EnableHistory is true, the HistoryOptions property (type HistoryTransportOptions) controls retention. See MessageHistory for the full list of history options.
The Memory transport can be monitored via the Dashboard using MemoryDashboardInit as the transport init type.
For any issues please use the GitHub issues