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
| Intent | API | Package role |
|---|---|---|
| Accept command for later execution | IInbox.AcceptAsync | LiteBus.Inbox |
| Enqueue event for later publication | IOutbox.EnqueueAsync | LiteBus.Outbox |
| Schedule with future visibility | InboxAcceptMetadata.Visibility / OutboxEnqueueMetadata.Visibility | MessageVisibility.At or MessageVisibility.After on the writer item |
| Execute command now | ICommandMediator.SendAsync | LiteBus.Commands |
| Publish event now | IEventMediator.PublishAsync | LiteBus.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.
| Extension | NuGet 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)
| Extension | NuGet 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)
| Extension | NuGet 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
| Option | Default | Notes |
|---|---|---|
HonorShutdownTokenOnPersist | false | When false, terminal PersistAsync uses CancellationToken.None (safer against duplicate dispatch; shutdown may block). When true, passes the shutdown token (faster drain; duplicate-dispatch risk). |
DispatcherConcurrency | 1 | Raise only when handlers are safe in parallel. |
LeaseHeartbeatInterval | 15s | Must be <= LeaseDuration / 2. |
Naming Schemes
| You see | Meaning |
|---|---|
Folder / project LiteBus.Inbox.Storage.PostgreSql | Source layout |
Namespace LiteBus.Inbox.Storage.PostgreSql | C# API |
NuGet LiteBus.Inbox.Storage.PostgreSql | Package ID |
Next
- Getting Started for a full walkthrough
- Inbox and Outbox for durable messaging depth
- Hosted services for manifest, probes, and management endpoints
- Dependency Graph for package boundaries