Path: redb-route/redb.Route.Sqs/SqsAckAction.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.Sqs/SqsAckAction.cs
----
using Amazon.SQS;
using redb.Route.Abstractions;
namespace redb.Route.Sqs;
///
/// Deferred SQS acknowledgement enrolled as an when the endpoint is
/// transacted=true. Commit deletes the message (or is a no-op when deleteAfterRead=false);
/// rollback resets its visibility to 0 so the broker redelivers it immediately. The surrounding
/// TransactedProcessor drives commit/rollback together with any redb DB work.
///
internal sealed class SqsAckAction : ITransactedAction
{
private readonly IAmazonSQS _client;
private readonly string _queueUrl;
private readonly string _receiptHandle;
private readonly bool _deleteAfterRead;
private int _settled;
public SqsAckAction(IAmazonSQS client, string queueUrl, string receiptHandle, bool deleteAfterRead)
{
_client = client;
_queueUrl = queueUrl;
_receiptHandle = receiptHandle;
_deleteAfterRead = deleteAfterRead;
}
/// True once commit or rollback has run — guards against a double settle.
public bool Settled => Volatile.Read(ref _settled) == 1;
///
public async Task Commit(CancellationToken ct = default)
{
if (Interlocked.CompareExchange(ref _settled, 1, 0) != 0) return;
if (_deleteAfterRead)
await _client.DeleteMessageAsync(_queueUrl, _receiptHandle, ct).ConfigureAwait(false);
}
///
public async Task Rollback(CancellationToken ct = default)
{
if (Interlocked.CompareExchange(ref _settled, 1, 0) != 0) return;
await _client.ChangeMessageVisibilityAsync(_queueUrl, _receiptHandle, 0, ct).ConfigureAwait(false);
}
}