API reference — Workflows

Nuvora.Nexus.Relay.Sagas.ValKey

ValKey saga persistence for Nuvora Nexus Relay (works with any Redis-compatible server)

dotnet add package Nuvora.Nexus.Relay.Sagas.ValKey

Nuvora.Nexus.Relay.Sagas.ValKey

ValKeySagaConcurrencyException

public sealed class ValKeySagaConcurrencyException : InvalidOperationException

Thrown when a saga save loses an optimistic-concurrency race (another delivery committed the same instance first). The losing delivery fails and is redelivered (inbox) or retried (scheduler), which re-reads the fresh state — the same recovery path as the EF Core repository’s DbUpdateConcurrencyException.

Constructors

ValKeySagaConcurrencyException(string sagaType, Guid sagaId)

ValKeySagaConnection

public sealed class ValKeySagaConnection : IAsyncDisposable

Owns the one multiplexed ValKey connection shared by the saga repository and read store (StackExchange.Redis is designed around a single shared multiplexer per endpoint). Connects lazily on first use.

Constructors

ValKeySagaConnection(IOptions<ValKeySagaOptions> options)

Methods

IDatabase GetDatabase()

Synchronous variant for the repository’s staging methods (ISagaRepository.Add/Update are synchronous by contract); only the very first call may block, on the initial connect.

ValueTask DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

ValueTask<IDatabase> GetDatabaseAsync(CancellationToken cancellationToken = default(CancellationToken))

The default database of the shared connection, connecting on first call.

ValKeySagaOptions

public sealed class ValKeySagaOptions

Options for the ValKey saga repository and read store.

Properties

string ConnectionString { get; set; }

StackExchange.Redis connection string (e.g. localhost:6379).

string KeyPrefix { get; set; }

Key prefix namespacing all saga keys per service/environment. The repository’s save scripts touch several keys atomically, so on a clustered deployment the prefix must contain a hash tag (e.g. {relay-sagas}:) to co-locate every saga key in one slot; the default targets non-clustered servers.

ValKeySagaReadStore

public sealed class ValKeySagaReadStore : ISagaReadStore

ValKey ISagaReadStore for operator dashboards. Listing walks the last-updated sorted set newest-first in pages, fetches the referenced records and filters client-side; counts read the per-status sets the repository maintains. Background-safe: uses the shared connection, no ambient transaction.

Constructors

ValKeySagaReadStore(IOptions<ValKeySagaOptions> options, ValKeySagaConnection connection)

Methods

Task<IReadOnlyList<SagaSummary>> ListAsync(string? sagaType = null, SagaStatus? status = null, int maxCount = 100, CancellationToken cancellationToken = default(CancellationToken))

List saga instances, newest-updated first, optionally filtered by type and/or status.

Task<SagaCounts> CountAsync(CancellationToken cancellationToken = default(CancellationToken))

Aggregate counts grouped by status across all saga types.

ValKeySagaRepository

public sealed class ValKeySagaRepository : ISagaRepository

ValKey saga repository. Each instance is a JSON value at {prefix}saga:{type}:{id} with a correlation index ({prefix}saga-corr:{type}:{tenant}:{key}), a last-updated sorted set and per-status sets for the read store — all maintained atomically by Lua scripts. Optimistic concurrency: a save asserts the stored version is exactly the loaded one (the coordinator increments Version once per delivery), so two concurrent deliveries to the same saga cannot both commit — the loser throws ValKeySagaConcurrencyException and is redelivered against fresh state.

Durability semantics. Unlike the EF Core repository, a save here does not join the command’s database transaction: the state write commits when Add/Update runs (the coordinator’s last step), while outbox/scheduler rows commit with the surrounding unit of work. If the process dies between the two, the redelivered message replays the transition on already-advanced state — the same at-least-once contract as any non-transactional saga store, so saga logic should tolerate a replayed trigger (or stay on the EF Core repository when it cannot).

Clustering. The save scripts touch several keys atomically, which requires all saga keys in one hash slot: on a clustered deployment set a hash-tagged ValKeySagaOptions.KeyPrefix (e.g. {relay-sagas}:).

Constructors

ValKeySagaRepository(IOptions<ValKeySagaOptions> options, ValKeySagaConnection connection)

Methods

Task<SagaRecord?> FindAsync(string sagaType, string correlationKey, Guid? tenantId, CancellationToken cancellationToken = default(CancellationToken))

Find the live instance for a correlation within a tenant (tracked), or null.

Task<SagaRecord?> FindByIdAsync(string sagaType, Guid sagaId, CancellationToken cancellationToken = default(CancellationToken))

Find an instance by id (tracked), or null.

void Add(SagaRecord saga)

Stage a new instance (insert).

void Update(SagaRecord saga)

Stage an update to a tracked instance (the concurrency token guards the write).

Nuvora.Nexus.Relay.Sagas.ValKey.DependencyInjection

ValKeySagaServiceCollectionExtensions

public static class ValKeySagaServiceCollectionExtensions

Registration helpers for the ValKey saga repository and read store.

Methods

static IServiceCollection AddRelaySagasReadStoreValKey(this IServiceCollection services)

Registers the background-safe read-only saga store (ISagaReadStore) for monitoring dashboards, over the indexes the ValKey repository maintains. Requires ValKeySagaServiceCollectionExtensions.AddRelaySagasValKey.

static IServiceCollection AddRelaySagasValKey(this IServiceCollection services, Action<ValKeySagaOptions> configure)

Registers the ValKey saga repository. Saga state is saved with optimistic concurrency when the coordinator stages it (not with the surrounding database transaction) — see ValKeySagaRepository for the at-least-once semantics this implies.