Path: redb-route/redb.Route.Sqs/Fluent/AwsDsl.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/Fluent/AwsDsl.cs
----
using redb.Route.Core;
namespace redb.Route.Sqs.Fluent;
///
/// Fluent URI builder entry point for Amazon SQS queues. Produces a sqs://queue-name?... URI
/// that drops straight into .From(...) / .To(...).
///
/// From(Sqs.Queue("orders").WaitTimeSeconds(20).ConcurrentConsumers(4))
/// .Process(...);
/// To(Sqs.Queue("orders").Region("eu-west-1"));
///
///
public static class Sqs
{
/// Starts an SQS endpoint builder for the given queue name (use the .fifo suffix for FIFO queues).
public static SqsBuilder Queue(string name) => new(name);
}
/// Fluent builder for an sqs:// endpoint URI.
public sealed class SqsBuilder
{
private readonly string _name;
private readonly Dictionary _params = new(StringComparer.Ordinal);
internal SqsBuilder(string name) => _name = name;
private SqsBuilder Set(string key, string value) { _params[key] = value; return this; }
// ── Connection / credentials ──
/// AWS region (e.g. us-east-1).
public SqsBuilder Region(string region) => Set("region", region);
/// Explicit service URL (LocalStack / ElasticMQ).
public SqsBuilder ServiceUrl(string url) => Set("serviceUrl", url);
/// Static access + secret keys.
public SqsBuilder Credentials(string accessKey, string secretKey) => Set("accessKey", accessKey).Set("secretKey", secretKey);
/// Session token for temporary (STS) credentials.
public SqsBuilder SessionToken(string token) => Set("sessionToken", token);
/// Named AWS profile.
public SqsBuilder Profile(string profileName) => Set("profileName", profileName);
/// Use the default AWS credential provider chain.
public SqsBuilder UseDefaultCredentials(bool value = true) => Set("useDefaultCredentialsProvider", value ? "true" : "false");
/// Reference a pre-registered connection factory by name.
public SqsBuilder ConnectionFactory(string name) => Set("connectionFactory", name);
/// Create the queue if it does not exist.
public SqsBuilder AutoCreateQueue(bool value = true) => Set("autoCreateQueue", value ? "true" : "false");
// ── Consumer ──
/// Long-poll wait time in seconds (0–20).
public SqsBuilder WaitTimeSeconds(int seconds) => Set("waitTimeSeconds", seconds.ToString());
/// Messages fetched per receive (1–10).
public SqsBuilder MaxNumberOfMessages(int count) => Set("maxNumberOfMessages", count.ToString());
/// Visibility timeout in seconds.
public SqsBuilder VisibilityTimeout(int seconds) => Set("visibilityTimeout", seconds.ToString());
/// Number of concurrent receive loops.
public SqsBuilder ConcurrentConsumers(int count) => Set("concurrentConsumers", count.ToString());
/// Consumer parallelism as a string: a number or "auto" (= max(CPU, 2)).
public SqsBuilder ConcurrentConsumers(string count) => Set("concurrentConsumers", count);
/// Keep extending visibility while a message is processing (requires visibilityTimeout > 0).
public SqsBuilder ExtendMessageVisibility(bool value = true) => Set("extendMessageVisibility", value ? "true" : "false");
/// When a message is deleted: after the route (, default) or on receipt ().
public SqsBuilder AckMode(AckMode mode) => Set("ackMode", mode.ToString().ToLowerInvariant());
/// Reset visibility to 0 on failure for immediate redelivery.
public SqsBuilder ResetVisibilityOnFailure(bool value = true) => Set("resetVisibilityOnFailure", value ? "true" : "false");
/// Batch mode: the route gets a List<IMessage> of up to maxBatchMessages messages, deleted once after the route.
public SqsBuilder Batching(bool value = true) => Set("batching", value ? "true" : "false");
/// Batch mode: largest number of messages in a batch (default 10).
public SqsBuilder MaxBatchMessages(int count) => Set("maxBatchMessages", count.ToString());
/// Batch mode: a batch is sent on once no message came for this many milliseconds (default 1000).
public SqsBuilder PollTimeoutMs(int ms) => Set("pollTimeoutMs", ms.ToString());
/// Batch mode: a batch is sent on once this many milliseconds have passed since its first message.
public SqsBuilder BatchingIntervalMs(int ms) => Set("batchingIntervalMs", ms.ToString());
///
/// Sets transacted for a producer: true requires an enclosing .Transacted() block,
/// false sends at once even inside one; left unset, the producer follows the block.
///
public SqsBuilder Transacted(bool value = true) => Set("transacted", value ? "true" : "false");
// ── Producer ──
/// Delivery delay in seconds (0–900).
public SqsBuilder DelaySeconds(int seconds) => Set("delaySeconds", seconds.ToString());
/// FIFO message group id (constant or ${...} expression).
public SqsBuilder MessageGroupId(string value) => Set("messageGroupId", value);
/// FIFO deduplication id (constant or ${...} expression).
public SqsBuilder MessageDeduplicationId(string value) => Set("messageDeduplicationId", value);
/// Sets an arbitrary URI parameter not covered by a typed method.
public SqsBuilder Param(string key, string value) => Set(key, value);
/// Builds the sqs:// URI.
public string Build()
{
var qs = string.Join("&", _params.Select(kv => $"{kv.Key}={Uri.EscapeDataString(kv.Value)}"));
return qs.Length > 0 ? $"sqs://{_name}?{qs}" : $"sqs://{_name}";
}
///
public override string ToString() => Build();
/// Implicit conversion to the URI string.
public static implicit operator string(SqsBuilder builder) => builder.Build();
}
///
/// Fluent URI builder entry point for Amazon SNS topics. Produces a sns://topic-name?... URI.
/// SNS is publish-only.
///
/// To(Sns.Topic("events").Region("us-east-1"));
///
///
public static class Sns
{
/// Starts an SNS endpoint builder for the given topic name (use the .fifo suffix for FIFO topics).
public static SnsBuilder Topic(string name) => new(name);
}
/// Fluent builder for an sns:// endpoint URI.
public sealed class SnsBuilder
{
private readonly string _name;
private readonly Dictionary _params = new(StringComparer.Ordinal);
internal SnsBuilder(string name) => _name = name;
private SnsBuilder Set(string key, string value) { _params[key] = value; return this; }
/// AWS region (e.g. us-east-1).
public SnsBuilder Region(string region) => Set("region", region);
/// Explicit service URL (LocalStack).
public SnsBuilder ServiceUrl(string url) => Set("serviceUrl", url);
/// Static access + secret keys.
public SnsBuilder Credentials(string accessKey, string secretKey) => Set("accessKey", accessKey).Set("secretKey", secretKey);
/// Named AWS profile.
public SnsBuilder Profile(string profileName) => Set("profileName", profileName);
/// Use the default AWS credential provider chain.
public SnsBuilder UseDefaultCredentials(bool value = true) => Set("useDefaultCredentialsProvider", value ? "true" : "false");
/// Reference a pre-registered connection factory by name.
public SnsBuilder ConnectionFactory(string name) => Set("connectionFactory", name);
/// Explicit topic ARN (skips name resolution).
public SnsBuilder TopicArn(string arn) => Set("topicArn", arn);
/// Create the topic if it does not exist.
public SnsBuilder AutoCreateTopic(bool value = true) => Set("autoCreateTopic", value ? "true" : "false");
/// Message subject (email delivery; constant or ${...}).
public SnsBuilder Subject(string subject) => Set("subject", subject);
/// Message structure (json for per-protocol payloads).
public SnsBuilder MessageStructure(string structure) => Set("messageStructure", structure);
/// FIFO message group id.
public SnsBuilder MessageGroupId(string value) => Set("messageGroupId", value);
/// FIFO deduplication id.
public SnsBuilder MessageDeduplicationId(string value) => Set("messageDeduplicationId", value);
/// Subscribe the given SQS queue ARN to this topic at start.
public SnsBuilder SubscribeSnsToSqs(string queueArn) => Set("subscribeSnsToSqs", "true").Set("subscribeQueueArn", queueArn);
///
/// On the auto-created SNS→SQS subscription, enable raw message delivery — the queue receives the
/// bare payload (and SNS attributes map to SQS attributes) instead of the JSON notification envelope.
///
public SnsBuilder RawMessageDelivery(bool value = true) => Set("rawMessageDelivery", value ? "true" : "false");
///
/// Sets transacted: true requires an enclosing .Transacted() block, false publishes at
/// once even inside one; left unset, the publish follows the block.
///
public SnsBuilder Transacted(bool value = true) => Set("transacted", value ? "true" : "false");
/// Sets an arbitrary URI parameter not covered by a typed method.
public SnsBuilder Param(string key, string value) => Set(key, value);
/// Builds the sns:// URI.
public string Build()
{
var qs = string.Join("&", _params.Select(kv => $"{kv.Key}={Uri.EscapeDataString(kv.Value)}"));
return qs.Length > 0 ? $"sns://{_name}?{qs}" : $"sns://{_name}";
}
///
public override string ToString() => Build();
/// Implicit conversion to the URI string.
public static implicit operator string(SnsBuilder builder) => builder.Build();
}