Atya.Messaging.Outbox
2.0.0
Prefix Reserved
dotnet add package Atya.Messaging.Outbox --version 2.0.0
NuGet\Install-Package Atya.Messaging.Outbox -Version 2.0.0
<PackageReference Include="Atya.Messaging.Outbox" Version="2.0.0" />
<PackageVersion Include="Atya.Messaging.Outbox" Version="2.0.0" />
<PackageReference Include="Atya.Messaging.Outbox" />
paket add Atya.Messaging.Outbox --version 2.0.0
#r "nuget: Atya.Messaging.Outbox, 2.0.0"
#:package Atya.Messaging.Outbox@2.0.0
#addin nuget:?package=Atya.Messaging.Outbox&version=2.0.0
#tool nuget:?package=Atya.Messaging.Outbox&version=2.0.0
Atya.Messaging.Outbox
Transactional outbox store and relay primitives for reliable Atya messaging.
Overview
Atya.Messaging.Outbox captures messages in an outbox store through the existing IMessagePublisher<TMessage> contract, then relays pending messages through a transport publisher later. The package includes contracts, serialization helpers, an in-memory store for tests and simple hosts, and a relay that preserves message id, correlation id, headers, and runtime message type. Delivery uses atomic claims with leases, backoff and sanitized failure diagnostics; failures that exhaust the attempt budget are marked Failed.
Entity Framework and broker-specific providers are intentionally out of scope for this package.
Installation
dotnet add package Atya.Messaging.Outbox
Quick Start
using Atya.Messaging.Abstractions;
using Atya.Messaging.Outbox;
var registry = new OutboxContractRegistry().Register<OrderSubmitted>("orders.submitted", schemaVersion: 1);
var store = new InMemoryOutboxStore(TimeProvider.System);
var outboxPublisher = new OutboxPublisher<OrderSubmitted>(store, TimeProvider.System, new OutboxMessageSerializer(registry));
await outboxPublisher.PublishAsync(
new OrderSubmitted("order-123"),
new MessagePublishOptions(messageId: "message-123", correlationId: "correlation-123"));
IMessagePublisher transportPublisher = /* adapter implemented by a transport package */;
var relay = new OutboxRelay(store, transportPublisher, TimeProvider.System, registry, new OutboxRelayOptions());
OutboxRelayResult result = await relay.PublishPendingAsync();
public sealed record OrderSubmitted(string OrderId);
Public Surface
IOutboxStorestores messages and arbitrates delivery:ClaimAsyncatomically claims a batch under oneOutboxClaimTokenand lease;RenewAsync,MarkPublishedAsyncandMarkFailedAsyncare compare-and-set on the token and returnOutboxTransition(Applied,ClaimLost,NotFound). Durable implementations must makeAddAsyncparticipate in the caller's transaction.OutboxMessagecarries a contract name and schema version (never a CLR type name),NextAttemptAt, claim owner/token/expiry and a sanitizedLastFailure.OutboxMessageStatushasPending,Claimed,Publishedand terminalFailed.OutboxContractRegistrymaps("orders.submitted", 1)to a type by dictionary lookup; there is noType.GetTypefallback and the registry is frozen on first use. Upcasters are not provided: an unknown name or version is a terminal failure.OutboxRelayclaims, renews the lease when under half remains, publishes, and acknowledges. Failures back off asmin(Max, Initial * Factor^(attempt-1))withJitterFactorjitter (set 0 in tests). Unknown contracts and undeserializable payloads are terminal immediately; other failures are terminal afterMaxAttempts.OutboxFailurepersists the exception type, a bounded and redacted description (type name only unlessDescribeFailuresupplies more) and a handle under which the full exception is logged. No stack trace is persisted.InMemoryOutboxStoreis an ephemeral, single-process store for tests and contract exercises. It is not a production outbox and does not enlist in transactions; the contract is theOutboxStoreConformanceTestssuite.
Delivery guarantee
Delivery is at least once. If acknowledging fails after a successful publish, no failure is recorded: the lease lapses and the message is sent again. Pair consumers with the Idempotency package keyed on the message id.
Hosting recipe
Run the relay on PeriodicBackgroundService from Atya.Hosting.BackgroundServices 2.0 (a recipe, not a package): derive a worker whose ExecuteIterationAsync calls relay.PublishPendingAsync(cancellationToken), register it with AddAtyaBackgroundService<RelayWorker>(o => o.Interval = TimeSpan.FromSeconds(2)), and note that failures inside the relay are recorded per message, not thrown.
Migrating from 1.x to 2.0
- Breaking for store implementers (claim-based contract), for code constructing
OutboxRelay(takesTimeProvider, a registry and options) and for stored data. - Register every message type with a contract name; rows written by 1.x carry assembly-qualified names. No mapping helper is shipped (no durable store exists yet), so 1.x pending rows become terminal "unknown contract" failures.
OutboxMessage.LastErrorbecameLastFailure;OutboxMessageSerializer.ResolveMessageTypewas removed;Atya.Foundation.Timeis no longer used.- Last compatible version: 1.0.0.
Testing
dotnet test
Benchmarks
dotnet run -c Release --project benchmarks/Outbox.Benchmarks
License
MIT. See LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Atya.Foundation.Guards (>= 1.1.0)
- Atya.Foundation.Serialization (>= 1.1.0)
- Atya.Messaging.Abstractions (>= 1.1.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.15)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.