Path: redb-route/redb.Route.Core/Transactions/RedbTransactedAction.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Core/Transactions/RedbTransactedAction.cs
----
using redb.Core.Data;
using redb.Route.Abstractions;
namespace redb.Route.RedbCore.Transactions;
///
/// Adapter that bridges to the route-pipeline
/// contract used by TransactedProcessor and
/// BeginTransactionProcessor.
///
/// Allows an explicit redb-level transaction to be enrolled in the standard
/// exchange.Properties["TRANSACT_ACTION"] dictionary so that it commits or rolls back
/// alongside other transports (Kafka, Redis, etc.) via the existing pipeline machinery,
/// instead of forcing route authors to write try/catch blocks around
/// .
///
///
/// On the underlying is committed and disposed;
/// on it is rolled back and disposed. The instance is single-use.
///
///
/// Note: /
/// do not accept a , so the token passed to
/// is intentionally ignored.
///
///
public sealed class RedbTransactedAction : ITransactedAction
{
private readonly IRedbTransaction _tx;
private int _completed;
/// Creates a new adapter wrapping the given redb transaction.
/// An open redb transaction. Must not be null.
/// Thrown when is null.
public RedbTransactedAction(IRedbTransaction tx)
{
_tx = tx ?? throw new ArgumentNullException(nameof(tx));
}
/// The wrapped redb transaction (for diagnostics / advanced scenarios).
public IRedbTransaction Transaction => _tx;
///
public async Task Commit(CancellationToken ct = default)
{
if (Interlocked.Exchange(ref _completed, 1) != 0)
return;
try
{
if (_tx.IsActive)
await _tx.CommitAsync().ConfigureAwait(false);
}
finally
{
await _tx.DisposeAsync().ConfigureAwait(false);
}
}
///
public async Task Rollback(CancellationToken ct = default)
{
if (Interlocked.Exchange(ref _completed, 1) != 0)
return;
try
{
if (_tx.IsActive)
await _tx.RollbackAsync().ConfigureAwait(false);
}
finally
{
await _tx.DisposeAsync().ConfigureAwait(false);
}
}
}