Repository navigation
MemoryTransport
The Memory transport stores messages in-process in concurrent collections. It has no external dependencies. It is a good fit for testing, prototyping, and single-process scenarios.
It supports the following features:
- History tracking (opt-in, the only configurable feature)
- Job scheduler
You do not need to create the queues before you use them. The transport allocates storage 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. It is included in the core DotNetWorkQueue NuGet package. You do not need a separate transport NuGet package.
[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.
You can monitor the Memory transport with the Dashboard. Use MemoryDashboardInit as the transport init type.
For any issues please use the GitHub issues