API reference — Reliable messaging
Nuvora.Nexus.Relay.Outbox.EfCore
EF Core (PostgreSQL) transactional outbox for Nuvora Nexus Relay
dotnet add package Nuvora.Nexus.Relay.Outbox.EfCore
Nuvora.Nexus.Relay.Outbox.EfCore
EfCoreOutboxRepository<TContext>
public sealed class EfCoreOutboxRepository<TContext> : IOutboxRepository where TContext : DbContext
EF Core (PostgreSQL) outbox repository. On the command path, EfCoreOutboxRepository.AddAsync/EfCoreOutboxRepository.AddManyAsync stage rows on the shared command DbContext so they commit atomically with the aggregate state and events. On the processor path, claiming and status updates use short-lived contexts from an IDbContextFactory and a FOR UPDATE SKIP LOCKED claim so multiple instances never publish the same message.
Constructors
EfCoreOutboxRepository(IRelayDbContextAccessor accessor, IDbContextFactory<TContext> contextFactory, IOptions<OutboxProcessorOptions> options, IRetryPolicy? retryPolicy = null)
Methods
Task AddAsync(OutboxMessage message, CancellationToken cancellationToken = default(CancellationToken))
Add a new message to the outbox (enlists in the ambient transaction; not flushed here).
Task AddManyAsync(IEnumerable<OutboxMessage> messages, CancellationToken cancellationToken = default(CancellationToken))
Add multiple messages to the outbox (enlists in the ambient transaction; not flushed here).
Task MarkAsProcessedAsync(Guid messageId, CancellationToken cancellationToken = default(CancellationToken))
Mark a claimed message as successfully processed.
Task<IReadOnlyList<OutboxMessage>> ClaimPendingAsync(int batchSize = 100, CancellationToken cancellationToken = default(CancellationToken))
Atomically claim up to batchSize due messages: rows are locked, marked as OutboxMessageStatus.Processing with a fresh claim timestamp, and returned in a single committed operation so no two instances claim the same message. Eligible rows are OutboxMessageStatus.Pending messages whose NextAttemptAt is due, plus OutboxMessageStatus.Processing rows whose claim is older than the processing lease — i.e. rows stranded by a crashed processor are recovered automatically.
Task<IReadOnlyList<OutboxMessage>> GetFailedMessagesAsync(int batchSize = 100, CancellationToken cancellationToken = default(CancellationToken))
Get messages that have been dead-lettered (for manual review/requeue).
Task<OutboxBacklog> GetBacklogAsync(CancellationToken cancellationToken = default(CancellationToken))
Counts rows by status for monitoring: pending backlog (due or not), in-flight (Processing) and dead-lettered totals, plus the age of the oldest pending row. Cheap aggregate query, intended for health checks and gauges.
Task<OutboxFailureOutcome> RecordFailureAsync(Guid messageId, string errorMessage, int maxRetries, CancellationToken cancellationToken = default(CancellationToken))
Record a processing failure against the live row: increments the retry count, sets the next backoff time, and dead-letters the message once maxRetries is reached. Reading the live row avoids the stale-retry-count bug of deciding from a batch snapshot.
Task<bool> DiscardFailedAsync(Guid messageId, CancellationToken cancellationToken = default(CancellationToken))
Permanently discards (deletes) one dead-lettered message. Operator action for messages that should never be replayed. Returns false when the row does not exist or is not dead-lettered.
Task<bool> RequeueFailedAsync(Guid messageId, CancellationToken cancellationToken = default(CancellationToken))
Requeues one dead-lettered (OutboxMessageStatus.Failed) message: resets its retry count and schedules it for immediate publication. The recovery path after fixing the defect that dead-lettered it. Returns false when the row does not exist or is not dead-lettered.
Task<int> DeleteProcessedMessagesAsync(DateTimeOffset olderThan, CancellationToken cancellationToken = default(CancellationToken))
Delete processed messages older than the specified date (cleanup).
Task<int> DiscardAllFailedAsync(int maxCount = 1000, CancellationToken cancellationToken = default(CancellationToken))
Permanently discards up to maxCount dead-lettered messages. Returns the count deleted.
Task<int> RequeueAllFailedAsync(int maxCount = 100, CancellationToken cancellationToken = default(CancellationToken))
Requeues up to maxCount dead-lettered messages (oldest first), resetting retry counts and scheduling immediate publication. Returns the number requeued.
PostgresClaimCheckStore<TContext>
public sealed class PostgresClaimCheckStore<TContext> : IClaimCheckStore where TContext : DbContext
Durable IClaimCheckStore backed by the relay_claim_checks table (BYTEA payload). Uses short-lived contexts from the IDbContextFactory (independent of the command transaction), since offload happens on the publish path and rehydrate on the consume path. Keeps offloaded payloads in the same database as everything else — same backup, RLS and maintenance.
Constructors
PostgresClaimCheckStore(IDbContextFactory<TContext> contextFactory)
Methods
Task DeleteAsync(string pointer, CancellationToken cancellationToken = default(CancellationToken))
Deletes a stored payload. No-op if the pointer is unknown.
Task<ClaimCheckPayload?> RetrieveAsync(string pointer, CancellationToken cancellationToken = default(CancellationToken))
Retrieves a previously stored payload, or null if the pointer is unknown.
Task<string> StoreAsync(byte[] payload, string contentType, CancellationToken cancellationToken = default(CancellationToken))
Stores payload and returns an opaque pointer used to retrieve it.
Nuvora.Nexus.Relay.Outbox.EfCore.DependencyInjection
ClaimCheckEfCoreServiceCollectionExtensions
public static class ClaimCheckEfCoreServiceCollectionExtensions
Registration helper for the PostgreSQL-backed claim-check store.
Methods
static IServiceCollection AddRelayClaimCheckPostgres<TContext>(this IServiceCollection services)
Replaces the claim-check store with PostgresClaimCheckStore. Requires an IDbContextFactory and the host context to call ApplyRelayClaimChecks() in OnModelCreating. Call alongside AddRelayClaimCheck (order-independent).
OutboxServiceCollectionExtensions
public static class OutboxServiceCollectionExtensions
Registration helpers for the EF Core (PostgreSQL) outbox repository.
Methods
static IServiceCollection AddRelayOutboxEfCore<TContext>(this IServiceCollection services)
Registers the EF Core outbox repository bound to TContext. Requires an IDbContextFactory for the processor’s independent connections — register one via AddDbContextFactory<TContext> (or AddDbContext<TContext>(..., optionsLifetime: ServiceLifetime.Singleton) plus AddDbContextFactory). The host context must call ApplyRelayOutbox() in OnModelCreating, and the event-store accessor must be registered (via AddRelayEventStoreEfCore).
Nuvora.Nexus.Relay.Outbox.EfCore.Persistence
ClaimCheckModelBuilderExtensions
public static class ClaimCheckModelBuilderExtensions
Maps the claim-check table (relay_claim_checks) onto the host’s DbContext. Call from OnModelCreating when using the Postgres-backed claim-check store.
Methods
static ModelBuilder ApplyRelayClaimChecks(this ModelBuilder modelBuilder)
OutboxModelBuilderExtensions
public static class OutboxModelBuilderExtensions
Maps the outbox table (relay_outbox_messages) onto the host’s DbContext. Call from OnModelCreating so outbox writes share the command’s transaction.
Methods
static ModelBuilder ApplyRelayOutbox(this ModelBuilder modelBuilder)
RelayClaimCheck
public class RelayClaimCheck
Row in relay_claim_checks: a message payload offloaded out-of-band (the “claim-check” pattern) so only the RelayClaimCheck.Pointer travels through the broker.
Properties
DateTimeOffset CreatedAt { get; set; }
When the row was created (used for TTL/maintenance pruning).
Guid Pointer { get; set; }
Opaque pointer / primary key referenced by the message’s claim-check header.
Guid? TenantId { get; set; }
Owning tenant (null = global / not tenant-scoped).
byte[] Payload { get; set; }
The offloaded payload bytes.
long SizeBytes { get; set; }
Payload size in bytes (for observability / pruning by volume).
string ContentType { get; set; }
Content type of the stored payload.