Skip to content

LiteDbTransport

blehnen edited this page Nov 10, 2026 · 5 revisions

LiteDb Transport

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)

The LiteDb transport does not support priority.

You must create the queue before you use the LiteDb transport. You can create it manually or with the queue creation classes.

Creating queues
//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();
        }
    }
 }
Usage

[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.

Full samples

See the LiteDb samples in the DotNetWorkQueue.Samples repository.

Clone this wiki locally