Yautbox 2.0.1

dotnet add package Yautbox --version 2.0.1
                    
NuGet\Install-Package Yautbox -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Yautbox" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Yautbox" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Yautbox" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Yautbox --version 2.0.1
                    
#r "nuget: Yautbox, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Yautbox@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Yautbox&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Yautbox&version=2.0.1
                    
Install as a Cake Tool

Yautbox

Yautbox is a lightweight .NET outbox library. It lets you enqueue messages during application work and process them later with background handlers. The core package is storage-agnostic; choose the in-memory or PostgreSQL provider, or implement your own.

Features

  • Outbox pattern with background processing
  • Typed handlers with retry support
  • Scheduled messages and visibility timeouts
  • Configurable concurrency, polling, and cleanup
  • Pluggable storage via IOutboxProvider

Delivery model

  • Delivery is at least once: a message can be delivered more than once when a handler succeeds but persisting its result fails.
  • Processing order is not guaranteed, especially with multiple workers or parallel batches.
  • Handlers must be idempotent.

Installation

NuGet:

dotnet add package Yautbox

From source:

dotnet add <your-app>.csproj reference src/Yautbox/Yautbox.csproj

Quick start

  1. Register the outbox and a provider.
using Microsoft.Extensions.DependencyInjection;
using Yautbox.Extensions.Ioc;
using Yautbox.InMemory.Extensions; // from Yautbox.InMemory package

services.AddOutbox(builder => builder.UseInMemory());
  1. Register a handler for a payload type.
using Yautbox.Extensions.Ioc;
using Yautbox.Handlers;

services.AddOutboxHandler<OrderPlaced, OrderPlacedHandler>();

public sealed class OrderPlacedHandler : IOutboxHandler<OrderPlaced>
{
    public Task HandleAsync(IEnumerable<OutboxMessage<OrderPlaced>> messages, CancellationToken ct)
    {
        foreach (var message in messages)
        {
            // process message.Payload
            // message.Retry(TimeSpan.FromMinutes(1)); // optional retry
        }

        return Task.CompletedTask;
    }
}
  1. Enqueue messages from your app code.
using Yautbox.Services;

await outbox.HandleAsync(new[] { new OrderPlaced("A-123") });
await outbox.HandleAsync(
    new[] { new OrderPlaced("B-456") },
    scheduledAt: DateTimeOffset.UtcNow.AddMinutes(5));

Cancel by id if needed:

using Yautbox.Extensions.Outbox;

await outbox.CancelAsync<OrderPlaced>(messageId);

For a heterogeneous batch, use IPolymorphicOutboxService. Each payload is stored under its concrete runtime type and routed to that type's handler, while returned identifiers preserve input order.

Configuration options

Each handler can be configured via AddOutboxHandler().ConfigureOptions<TOptions>(). Implement IOutboxRunnerOptions<TPayload> for full control or ISimpleRunnerOptions<TPayload> when only BufferSize must be supplied.

using Microsoft.Extensions.Options;
using Yautbox.Extensions.Ioc;
using Yautbox.Runner.Options;

public sealed class OrderPlacedOptions : ISimpleRunnerOptions<OrderPlaced>
{
    public int BufferSize { get; set; } = 500;
    public int WorkersCount { get; set; } = 2;
    public TimeSpan? BackupInterval { get; set; } = TimeSpan.FromHours(24);
}

services
    .AddOutboxHandler<OrderPlaced, OrderPlacedHandler>()
    .ConfigureOptions<OrderPlacedOptions>(options =>
        options.Configure(o => o.BufferSize = 1000));

Options are bound to the handler payload: ConfigureOptions<TOptions>() accepts only types implementing IOutboxRunnerOptions<TPayload> for the payload of that handler. Without ConfigureOptions the defaults below are used.

IOutboxRunnerOptions<TPayload> settings and defaults:

  • Identifier (default: payload type assembly-qualified name without version, culture, or public key token)
  • PollDelay (default: 5s + jitter)
  • BufferSize (default: 1000)
  • PerBufferCount (default: BufferSize)
  • HandleTimeout (default: 55m)
  • IsEnabled (default: true)
  • WorkersCount (default: 1)
  • DeletePolicy (default: Safe)
  • FailureDelay (default: 2s + jitter)
  • Visibility (default: 1h)
  • BackupInterval (default: null, disabled)
  • CleanupInterval (default: 1d)
  • ExecutionPolicy (default: Parallel)
  • CancellationPolicy (default: Safe)
  • PolicyTimeout (default: 5s; if the scope is busy, the cycle is skipped until the next poll)
  • ScopeLifetime (default: PerBatch)
  • PartitionKey (default: null, not partitioned)

Options validation

Options are validated when a runner starts and after every options reload. All problems are reported at once:

  • Failures (for example, non-positive delays or sizes, PerBufferCount > BufferSize, RetryCount <= 0, RetryDelays with zero or negative values, Sequential with PerBufferCount != BufferSize) are logged at Error level and stop the runner. With the default BackgroundServiceExceptionBehavior.StopHost the application stops, so a misconfigured handler fails fast instead of silently doing nothing.
  • Warnings are only logged: Sequential without RetryCount and RetryDelays (a failing message holds back the queue indefinitely), and PartitionKey with ScopeLifetime.PerGroup or PerSession (one handler instance is called concurrently).

A disabled handler (IsEnabled = false) is not validated.

Partitioning

Set PartitionKey to partition the messages of a cycle. The messages fetched in one cycle are grouped by the key before being split into PerBufferCount chunks, so one HandleAsync call never mixes different keys. Chunks are handled concurrently. With ExecutionPolicy.Sequential this is the way to parallelize processing inside the acquired scope when messages with different keys can be handled independently.

public sealed class OrderPlacedOptions : ISimpleRunnerOptions<OrderPlaced>
{
    public int BufferSize => 500;
    ExecutionPolicy IOutboxRunnerOptions<OrderPlaced>.ExecutionPolicy => ExecutionPolicy.Sequential;
    Func<OrderPlaced, object?>? IOutboxRunnerOptions<OrderPlaced>.PartitionKey => message => message.OrderId;
}

Register it with AddOutboxHandler<OrderPlaced, OrderPlacedHandler>().ConfigureOptions<OrderPlacedOptions>().

With ScopeLifetime.PerGroup or PerSession all chunks share one handler instance, which must then be thread-safe.

How it works

  • IOutboxService enqueues messages into an IOutboxProvider.
  • AddOutboxHandler<TPayload, THandler>() registers two hosted services:
    • a handler runner that polls, locks, and dispatches messages
    • a cleanup runner that deletes old handled records when BackupInterval is set
  • ExecutionPolicy.Sequential uses a provider-level policy scope to ensure single active processing for the same identifier: an advisory lock for Postgres, an in-process lock for InMemory. Several workers (WorkersCount > 1) and instances may run; only the one holding the scope processes a cycle, the others skip it until the next poll.

Extensibility

To create a custom storage implementation, implement IOutboxProvider and register it via AddOutbox(builder => builder.SetProvider<...>()).

Metrics

Yautbox reports lifecycle metrics through IMetricsHandler. The default handler is a no-op. Register a custom handler via the infrastructure builder:

using Yautbox.Extensions.Ioc;
using Yautbox.Metrics;

services.AddOutbox(builder =>
{
    builder.UseInMemory();
    builder.SetMetrics<MyMetricsHandler>();
});

public sealed class MyMetricsHandler : IMetricsHandler
{
    public ValueTask AddedAsync(string identifier, int count, CancellationToken ct) => ValueTask.CompletedTask;
    public ValueTask CanceledAsync(string identifier, int count, CancellationToken ct) => ValueTask.CompletedTask;
    public ValueTask HandledAsync(string identifier, int count, TimeSpan elapsed, CancellationToken ct) => ValueTask.CompletedTask;
    public ValueTask RetriedAsync(string identifier, int count, CancellationToken ct) => ValueTask.CompletedTask;
    public ValueTask DeletedAsync(string identifier, int count, CancellationToken ct) => ValueTask.CompletedTask;
    public ValueTask CleanedInAsync(string identifier, TimeSpan elapsed, CancellationToken ct) => ValueTask.CompletedTask;
    public ValueTask ReadInAsync(string identifier, TimeSpan elapsed, CancellationToken ct) => ValueTask.CompletedTask;
    public ValueTask ErrorsAsync(string identifier, int count, CancellationToken ct) => ValueTask.CompletedTask;

    // Optional: default implementations are no-ops.
    public ValueTask CycledAsync(string identifier, CancellationToken ct) => ValueTask.CompletedTask;
    public ValueTask CycledFailedAsync(string identifier, CancellationToken ct) => ValueTask.CompletedTask;
}

CycledAsync and CycledFailedAsync report every worker processing loop that ended normally or with an error. They have default no-op implementations, so existing handlers keep compiling.

Tracing

Yautbox creates tracing scopes for enqueue, fetch, handle, persist, and cleanup through IOutboxTracer. The default tracer is a no-op. Register an Activity/OpenTelemetry adapter with builder.SetTracing<MyOutboxTracer>().

Target frameworks

net8.0

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Yautbox:

Package Downloads
Yautbox.Postgres

PostgreSQL provider for Yautbox with schema migrations and advisory locks for sequential execution.

Yautbox.InMemory

In-memory Yautbox provider using a bounded in-process queue. Ideal for tests and local development where durability is not required.

Yautbox.Mssql

SQL Server provider for Yautbox with schema migrations and distributed locks for sequential execution.

Yautbox.Mysql

MySQL provider for Yautbox with schema migrations and distributed locks for sequential execution.

Yautbox.Testing

Unit-testing helpers for Yautbox: builds OutboxMessage instances so outbox handlers can be tested without storage or a host.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 62 11/22/2026
1.4.0 206 8/15/2026
1.3.0 232 7/6/2026
1.2.1 195 5/22/2026
1.1.1 216 3/1/2026
1.1.0 215 2/23/2026
1.0.1 210 2/14/2026
1.0.0 190 2/14/2026