LiteBus
Getting started

LiteBus Cheat Sheet

One-page reference for LiteBus v6. Install only the packages you use; register storage, dispatch, and processors inside nested inbox/outbox builders.

Mediators

Inject ICommandMediator, IQueryMediator, or IEventMediator. Handlers and pipeline stages (pre, post, error) are discovered by RegisterFromAssembly and resolved per mediation call.

await commandMediator.SendAsync(new CreateOrderCommand(orderId));
var order = await queryMediator.QueryAsync(new GetOrderQuery(orderId));
await eventMediator.PublishAsync(new OrderPlaced(orderId));

Module Registration

Prefer the ILiteBusBuilder overload for normal package-owned feature composition:

services.AddLiteBus(builder =>
{
    var assembly = typeof(Program).Assembly;

    builder.AddMessaging(messaging =>
        messaging.Contracts.Register<OrderPlaced>("orders.events.placed", 1));
    builder.AddCommands(c => c.RegisterFromAssembly(assembly));
    builder.AddQueries(q => q.RegisterFromAssembly(assembly));
    builder.AddEvents(e => e.RegisterFromAssembly(assembly));

    builder.AddInbox(inbox =>
    {
        inbox.Contracts.Register<ProcessPaymentCommand>("payments.process-payment", 1);
        inbox.UseInMemoryStorage();
        inbox.UseInProcessDispatch();
        inbox.EnableInboxProcessor(host => host.PollInterval = TimeSpan.FromSeconds(2));
    });

    builder.AddOutbox(outbox =>
    {
        outbox.Contracts.Register<OrderPlaced>("orders.events.placed", 1);
        outbox.UseInMemoryStorage();
        outbox.UseInProcessDispatch();
        outbox.EnableOutboxProcessor(host => host.PollInterval = TimeSpan.FromSeconds(2));
    });
});

Durable Messaging Entry Points

IntentAPIPackage role
Accept command for later executionIInbox.AcceptAsyncLiteBus.Inbox
Enqueue event for later publicationIOutbox.EnqueueAsyncLiteBus.Outbox
Schedule with future visibilityInboxAcceptMetadata.Visibility / OutboxEnqueueMetadata.VisibilityMessageVisibility.At or MessageVisibility.After on the writer item
Execute command nowICommandMediator.SendAsyncLiteBus.Commands
Publish event nowIEventMediator.PublishAsyncLiteBus.Events

Only ICommand (no result) may be stored in the inbox. Analyzer LB1004 flags ICommand<TResult> at compile time.

Root Transport Composition

Register horizontal transport infrastructure once on ILiteBusBuilder. Dispatch and ingress extensions require and share it.

ExtensionNuGet package
AddAmqpTransport(...)LiteBus.Transport.Amqp
AddKafkaTransport(...)LiteBus.Transport.Kafka
AddAwsSqsTransport(...)LiteBus.Transport.AwsSqs
AddAzureServiceBusTransport(...)LiteBus.Transport.AzureServiceBus
AddInMemoryTransport()LiteBus.Transport.InMemory

Inbox Composition (Use* Extensions)

ExtensionNuGet package
UseInMemoryStorage()LiteBus.Inbox.Storage.InMemory
UsePostgreSqlStorage(...)LiteBus.Inbox.Storage.PostgreSql
UseEntityFrameworkCoreStorage(...)LiteBus.Inbox.Storage.EntityFrameworkCore
UseInProcessDispatch()LiteBus.Inbox.Dispatch.InProcess
UseAmqpDispatch(...)LiteBus.Inbox.Dispatch.Amqp
UseAzureServiceBusDispatch(...)LiteBus.Inbox.Dispatch.AzureServiceBus
UseAwsSqsDispatch(...)LiteBus.Inbox.Dispatch.AwsSqs
UseKafkaDispatch(...)LiteBus.Inbox.Dispatch.Kafka
UseInMemoryDispatch(...)LiteBus.Inbox.Dispatch.InMemory
UseAmqpIngress(...)LiteBus.Inbox.Ingress.Amqp
UseAzureServiceBusIngress(...)LiteBus.Inbox.Ingress.AzureServiceBus
UseAwsSqsIngress(...)LiteBus.Inbox.Ingress.AwsSqs
UseKafkaIngress(...)LiteBus.Inbox.Ingress.Kafka
UseInMemoryIngress(...)LiteBus.Inbox.Ingress.InMemory
EnableInboxProcessor(...)LiteBus.Inbox (registers InboxProcessorBackgroundService via manifest)
EnableSaga(...)LiteBus.Saga.InboxIntegration

Outbox Composition (Use* Extensions)

ExtensionNuGet package
UseInMemoryStorage()LiteBus.Outbox.Storage.InMemory
UsePostgreSqlStorage(...)LiteBus.Outbox.Storage.PostgreSql
UseEntityFrameworkCoreStorage(...)LiteBus.Outbox.Storage.EntityFrameworkCore
UseInProcessDispatch()LiteBus.Outbox.Dispatch.InProcess
UseAmqpDispatch(...)LiteBus.Outbox.Dispatch.Amqp
UseAzureServiceBusDispatch(...)LiteBus.Outbox.Dispatch.AzureServiceBus
UseAwsSqsDispatch(...)LiteBus.Outbox.Dispatch.AwsSqs
UseKafkaDispatch(...)LiteBus.Outbox.Dispatch.Kafka
UseInMemoryDispatch(...)LiteBus.Outbox.Dispatch.InMemory
EnableOutboxProcessor(...)LiteBus.Outbox

Accept and Enqueue Examples

var receipt = await inbox.AcceptAsync(
    InboxAcceptItem<ProcessPaymentCommand>.From(
        new ProcessPaymentCommand(paymentId, amount),
        InboxAcceptMetadata.Immediate with
        {
            Idempotency = new Idempotency.Keyed($"payment:{paymentId}"),
        }),
    cancellationToken);

var outboxReceipt = await outbox.EnqueueAsync(
    OutboxEnqueueItem<OrderPlaced>.WithTopic(new OrderPlaced(orderId), "orders.events"),
    cancellationToken);

PostgreSQL Storage (Nested)

builder.AddInbox(inbox =>
{
    inbox.Contracts.Register<ProcessPaymentCommand>("payments.process-payment", 1);
    inbox.UsePostgreSqlStorage(pg =>
    {
        pg.UseDataSource(dataSource);
        pg.EnsureSchemaCreationOnStartup(); // dev only; production uses migration-owned DDL
    });
    inbox.UseInProcessDispatch();
    inbox.EnableInboxProcessor();
});

Inbox and outbox use PostgreSQL schema version 3; saga uses version 2. Apply the ordered migration files for an existing v6 table. Tables from v5 or earlier require replacement or an application-owned data migration.

Health and Operations

builder.Services.AddLiteBusManagement(options =>
{
    options.FailHealthWhenNoProbes = false; // samples; production should use true (default)
    options.AuthorizationPolicy = "LiteBusOperator"; // production
    // options.AllowAnonymousManagement = true; // Development only
});
builder.Services.AddHealthChecks().AddLiteBus();
app.UseAuthentication();
app.UseAuthorization();
app.AddLiteBusManagementEndpoints();

Register IDiagnosticCheck probes on the inbox or outbox builder with AddDiagnosticCheck<T>(name).

OpenTelemetry

The aggregate LiteBus.Extensions.OpenTelemetry package is removed. Register each axis you export:

builder.Services.AddOpenTelemetry()
    .WithMetrics(m => m
        .AddLiteBusInboxMetrics()
        .AddLiteBusOutboxMetrics()
        .AddLiteBusTransportMetrics());

Instrument names on LiteBusInboxTelemetry, LiteBusOutboxTelemetry, and LiteBusTransportTelemetry are a public contract; renames are breaking changes.

Processor Options Worth Knowing

OptionDefaultNotes
HonorShutdownTokenOnPersistfalseWhen false, terminal PersistAsync uses CancellationToken.None (safer against duplicate dispatch; shutdown may block). When true, passes the shutdown token (faster drain; duplicate-dispatch risk).
DispatcherConcurrency1Raise only when handlers are safe in parallel.
LeaseHeartbeatInterval15sMust be <= LeaseDuration / 2.

Naming Schemes

You seeMeaning
Folder / project LiteBus.Inbox.Storage.PostgreSqlSource layout
Namespace LiteBus.Inbox.Storage.PostgreSqlC# API
NuGet LiteBus.Inbox.Storage.PostgreSqlPackage ID

Next

On this page