-
Notifications
You must be signed in to change notification settings - Fork 16
LiteDbTransport
Brian Lehnen edited this page Apr 8, 2026
·
4 revisions
The LiteDb transport uses LiteDb databases to store messages. It supports the following features
- Delayed messages
- Message expiration
- Heartbeat (always enabled)
- Routing
- History tracking
- Status tracking (always enabled)
Priority is not supported by the LiteDb transport.
The LiteDb transport requires that the queue be created before usage. This can be done manually, or via the queue creation classes.
//Create the queue if it doesn't exist
var queueName = "testing";
//only shared connections are supported
var connectionString = @"Filename=c:\temp\queue.db;Connection=shared;";
var queueConnection = new QueueConnection(queueName, connectionString);
using (var createQueueContainer = new QueueCreationContainer<LiteDbMessageQueueInit>())
{
using (var createQueue = createQueueContainer.GetQueueCreation<LiteDbMessageQueueCreation>(queueConnection))
{
if (!createQueue.QueueExists)
{
createQueue.CreateQueue();
}
}
}[Producer]
using (var queueContainer = new QueueContainer<LiteDbMessageQueueInit>())
{
using (var queue = queueContainer.CreateProducer<SimpleMessage>(queueConnection))
{
queue.Send(new SimpleMessage { Message = "Hello World" });
}
}[Consumer]
using (var queueContainer = new QueueContainer<LiteDbMessageQueueInit>())
{
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.
If history tracking is enabled, see MessageHistory for retention and query options.
See the LiteDb samples in the DotNetWorkQueue.Samples repository.
For any issues please use the GitHub issues