AWS SQS Transport
The Amazon SQS transport (BareWire.Transport.AWS.SQS) implements BareWire's ITransportAdapter
on top of Amazon Simple Queue Service. It pairs a long-polling consumer with a batched producer
(up to 10 messages per SQS batch), tracks in-flight messages with credit-based flow control, and
dead-letters via SQS's native RedrivePolicy. FIFO queues, IAM instance-profile auth, and SSE
encryption at rest are all supported.
Registration
The ergonomic path is the bundle package BareWire.AWS.SQS, which registers the core engine and
the SQS transport in one call via AddBareWireWithSqs. The bus delegate is optional — omit it
when transport defaults are enough:
builder.Services.AddBareWireWithSqs(
transport => transport.Region("eu-central-1"),
bus =>
{
// middleware, serializers...
});
AddBareWireWithSqs is sugar over the explicit two-call form, which remains fully supported (use
it when you reference the core and transport packages separately):
builder.Services.AddBareWireSqs(transport => transport.Region("eu-central-1"));
builder.Services.AddBareWire(bus => { /* middleware, serializer mappings... */ });
Authentication
The transport supports three credential modes through ISqsConfigurator. Prefer the default
credential chain or an instance profile in production — both keep secrets out of application
configuration. The Secret Access Key is never logged and never appears in diagnostic output.
services.AddBareWireSqs(sqs =>
{
sqs.Region("eu-central-1");
// DefaultChain (recommended, default) — IAM role, env vars, shared credentials file:
sqs.UseDefaultCredentials();
// IAM instance profile (EC2 instance profile / ECS task role), credentials from IMDS:
// sqs.UseInstanceProfileCredentials(); // default role attached to the profile
// sqs.UseInstanceProfileCredentials("MyAppRole"); // or an explicit role name
// Explicit static credentials (local development only):
// sqs.UseExplicitCredentials("<access-key-id>", "<secret-access-key>");
});
For LocalStack or another SQS-compatible endpoint, point the adapter at a custom URL with
ServiceUrl. Plain http is rejected unless you also call AllowInsecureEndpoint() (test
environments only):
services.AddBareWireSqs(sqs =>
{
sqs.ServiceUrl("http://localhost:4566");
sqs.AllowInsecureEndpoint(); // opt out of TLS enforcement — test only
sqs.Region("us-east-1");
});
Receive endpoints
A receive endpoint binds one or more consumers to an SQS queue. The endpoint name is the queue name:
builder.Services.AddBareWireWithSqs(
transport =>
{
transport.Region("eu-central-1");
transport.MaxInFlightMessages(200);
transport.ReceiveEndpoint("orders", e =>
{
e.PrefetchCount = 32; // in-flight credit limit enforced by the BareWire core
e.ConcurrentMessageLimit = 8; // concurrent handler invocations
e.RetryCount = 3;
e.RetryInterval = TimeSpan.FromSeconds(1);
e.Consumer<OrderCreatedConsumer, OrderCreated>();
});
});
builder.Services.AddTransient<OrderCreatedConsumer>();
Consumers are resolved from the container, so register each consumer type (for example services.AddTransient<OrderCreatedConsumer>()). The queue must already exist — topology is manual, so provision it out of band (infrastructure
as code, the AWS console, or a deployment step) before the bus starts. An endpoint can also host a
raw consumer (e.RawConsumer<T>()), a saga state machine (e.StateMachineSaga<T>()), several typed
consumers, and per-key ordering; see Publishing and Consuming.
Things to know:
PrefetchCountis not an SQS setting. It is the credit limit the BareWire core uses to bound unsettled messages for the endpoint; the number of messages fetched per call is set byMaxNumberOfMessages.MaxInFlightMessagesis shared by all endpoints on the transport. Slots are reserved atomically before each receive call, and a receive call never asks SQS for more messages than the free slots, so a message is never received only to be skipped. Each endpoint also buffers at most itsPrefetchCountmessages. When the limit is exhausted, receiving pauses until a slot frees up. If a received message still cannot be registered, it is returned to the queue immediately (visibility timeout set to 0, in one batch call) instead of waiting for the visibility timeout to expire. SizingMaxInFlightMessagesto at least the sum of thePrefetchCountvalues of all endpoints is a performance hint, not a correctness requirement: with a smaller limit, an endpoint may wait up toWaitTimeSecondsfor a free slot.- Poison messages: a failing message is released for redelivery, and
Rejectdeliberately leaves the message on the queue. It only reaches a dead-letter queue if the source queue has aRedrivePolicy(maxReceiveCountplus a dead-letter queue). Without one, a poison message is redelivered indefinitely. IBus.ConnectReceiveEndpoint(adding an endpoint at runtime) is not supported yet; declare every endpoint in the transport delegate.- Only one transport can be registered per service collection: registering a second, different transport throws
BareWireConfigurationException, and support for hosting several transports in one service collection is planned. - Calling
AddBareWireSqsa second time on one service collection also throwsBareWireConfigurationException; declare every receive endpoint in a single call.
Long-polling consumer
Each receive endpoint runs one long-polling consumer loop on its queue, which
uses SQS long polling to minimise empty-receive calls. WaitTimeSeconds (0–20,
default 20) sets the poll duration, MaxNumberOfMessages (1–10, default 10) the batch size per
ReceiveMessage call, VisibilityTimeout (default 30 s) the window before an unsettled message
becomes visible again, and MaxInFlightMessages (default 100) bounds the consumed-but-unsettled
messages tracked in the in-flight registry. All four are set on ISqsConfigurator (see
Configurator options).
Batching
The producer groups outgoing messages into SQS send batches of up to 10, and the consumer
retrieves up to 10 messages per ReceiveMessage call. The transport advertises this through its
capability flags: NativeDeduplication | DlqNative | BatchReceive.
FIFO queues
FIFO fields are set only when the queue name ends in .fifo; standard queues are unaffected.
Declare a FIFO queue (and its DLQ redrive) through QueueDeclaration.Arguments:
new QueueDeclaration("my-orders.fifo", Arguments: new Dictionary<string, object>
{
["bw.sqs.fifo"] = true,
["bw.sqs.content-based-deduplication"] = true,
["bw.sqs.max-receive-count"] = 5,
});
MessageGroupId (the ordering boundary) resolves from the BW-MessageGroupId header, falling
back to the auto-stamped correlation-id header — which gives per-saga FIFO ordering with no extra
configuration. A FIFO send with no resolvable group id fails fast with BareWireTransportException.
MessageGroupId is an ordering boundary only, never an authorization or tenant-isolation boundary.
MessageDeduplicationId resolves in order: an explicit BW-MessageDeduplicationId header;
content-based dedup when enabled (the broker hashes the body); otherwise a deterministic id from a
SHA-256 hash of (MessageGroupId + body). Call ContentBasedDeduplication() on the configurator so
BareWire sends no explicit id (the queue must have ContentBasedDeduplication=true). On consume,
FIFO messages are stamped with broker-trusted BW-MessageGroupId and BW-SequenceNumber headers.
Settlement and dead-lettering
BareWire settlement actions map onto SQS operations as follows:
| BareWire action | SQS operation |
|---|---|
Ack |
DeleteMessage — permanent removal |
Nack / Requeue / Defer |
ChangeMessageVisibility(0) — release for redelivery |
Reject |
No operation — RedrivePolicy moves it to the DLQ once maxReceiveCount is exhausted |
SQS has no native dead-letter API, so Reject deliberately does not delete the message — that
would silently discard it without triggering the DLQ. Dead-lettering is a RedrivePolicy on the
queue, configured via the bw.sqs.max-receive-count argument (default 5).
See: Retry and Dead Letter Queues for the general retry/DLQ model.
Encryption at rest
Server-side encryption is a per-queue, opt-in attribute — a queue without an SSE argument is not
encrypted by BareWire. SSE-SQS (bw.sqs.sse-managed) and SSE-KMS (bw.sqs.kms-master-key-id, with
optional bw.sqs.kms-data-key-reuse-period) are mutually exclusive; setting both throws at deploy
time.
// SSE-KMS with a customer CMK
new QueueDeclaration("payments", Arguments: new Dictionary<string, object>
{
["bw.sqs.kms-master-key-id"] = "alias/my-cmk", // key id or ARN
["bw.sqs.kms-data-key-reuse-period"] = 300, // optional, 60–86400
});
Minimum IAM permissions
Grant the application role only what each part of the transport calls. Consuming a queue needs:
{
"Effect": "Allow",
"Action": [
"sqs:GetQueueUrl",
"sqs:ReceiveMessage",
"sqs:DeleteMessage",
"sqs:ChangeMessageVisibility"
],
"Resource": "arn:aws:sqs:eu-central-1:123456789012:orders"
}
sqs:ChangeMessageVisibility also covers the batch variant used to release messages. Publishing to
a queue needs sqs:GetQueueUrl and sqs:SendMessage (also used for batched sends). Deploying
topology is a separate concern: creating queues and configuring dead-letter redrive needs
sqs:CreateQueue, sqs:GetQueueAttributes and sqs:SetQueueAttributes. Give these topology
permissions to a deployment role rather than to the running application when you deploy topology out
of band. For a queue encrypted with a customer-managed KMS key, consumers additionally need
kms:Decrypt on that key and publishers need kms:GenerateDataKey.
Configurator options
ISqsConfigurator method |
Default | Description |
|---|---|---|
UseDefaultCredentials() |
(default) | AWS SDK default credential chain |
UseExplicitCredentials(key, secret) |
— | Static Access Key ID + Secret Access Key |
UseInstanceProfileCredentials(role?) |
— | IAM instance profile (EC2 / ECS task role) via IMDS |
Region(string) |
(env) | AWS region name (e.g. eu-central-1) |
ServiceUrl(string) |
(AWS) | Custom endpoint URL (LocalStack / SQS-compatible) |
AllowInsecureEndpoint() |
false | Opt out of TLS enforcement (test only) |
VisibilityTimeout(TimeSpan) |
30 s | Default message visibility timeout |
WaitTimeSeconds(int) |
20 | Long-poll wait time (0–20) |
MaxNumberOfMessages(int) |
10 | Max messages per ReceiveMessage (1–10) |
MaxInFlightMessages(int) |
100 | Max concurrent in-flight messages, shared by all receive endpoints |
ReceiveEndpoint(string, Action<IReceiveEndpointConfigurator>) |
none | Binds consumers to a queue (endpoint name = queue name) |
ContentBasedDeduplication() |
off | Skip explicit dedup id (broker hashes body) |