Configuration Options

Component: Amazon SQS Transport
NuGet Package NServiceBus.AmazonSQS (5.x)
Target NServiceBus Version: 7.x
The transport does not support transport.ConnectionString(...) to specify the connection string via code.

CredentialSource

Optional

Default: AWS SDK credentials

By default the endpoint uses the SDK to retrieve AWS credentials. The AWS SDK permits a large number of transparent methods for configuring the credentials as outlined in the .NET SDK guidelines.

Example: To manually control the credentials retrieval, specify:

var transport = endpointConfiguration.UseTransport<SqsTransport>();
transport.ClientFactory(() => new AmazonSQSClient(new InstanceProfileAWSCredentials()));

for S3 specify

var transport = endpointConfiguration.UseTransport<SqsTransport>();
var s3Configuration = transport.S3(bucketName, keyPrefix);
s3Configuration.ClientFactory(() => new AmazonS3Client(new InstanceProfileAWSCredentials()));

Region

Mandatory

Default: AWS SDK

By default the endpoint uses the SDK to retrieve the default AWS region from the AWS_REGION environment variable.

This is the Amazon Web Services Region in which to access the SQS service. The value must be a valid AWS region code.

Example: To manually control the region, specify

var transport = endpointConfiguration.UseTransport<SqsTransport>();
transport.ClientFactory(() => new AmazonSQSClient(
    new AmazonSQSConfig {
        RegionEndpoint = RegionEndpoint.APSoutheast2
    }));

for S3 specify

var transport = endpointConfiguration.UseTransport<SqsTransport>();
var s3Configuration = transport.S3(bucketName, keyPrefix);
s3Configuration.ClientFactory(() => new AmazonS3Client(
    new AmazonS3Config
    {
        RegionEndpoint = RegionEndpoint.APSoutheast2
    }));

ProxyHost and ProxyPort

Optional

Default: Empty

This is the name of the host of the proxy server that the client must authenticate to.

var transport = endpointConfiguration.UseTransport<SqsTransport>();
transport.ClientFactory(() => new AmazonSQSClient(
    new AmazonSQSConfig {
        ProxyCredentials = new NetworkCredential(userName, password),
        ProxyHost = "127.0.0.1",
        ProxyPort = 8888
    }));

for S3 specify

var transport = endpointConfiguration.UseTransport<SqsTransport>();
var s3Configuration = transport.S3(bucketName, keyPrefix);
s3Configuration.ClientFactory(() => new AmazonS3Client(
    new AmazonS3Config
    {
        ProxyCredentials = new NetworkCredential(userName, password),
        ProxyHost = "127.0.0.1",
        ProxyPort = 8888
    }));
It is discouraged to specify username and password in code.

Client Factory

Optional

Default: () => new AmazonSQSClient()

This overloads the default SQS client factory with a custom factory creation delegate.

Example: To use a custom factory, specify:

var transport = endpointConfiguration.UseTransport<SqsTransport>();
transport.ClientFactory(() => new AmazonSQSClient(new AmazonSQSConfig()));

MaxTTLDays

Optional

Default: 4

This is the maximum number of days that a message will be retained within SQS and S3. When a sent message is not received and successfully processed within the specified time, the message will be lost. This value applies to both SQS and S3 - messages in SQS will be deleted after this amount of time, and large message bodies stored in S3 will automatically be deleted after this amount of time.

The maximum value is 14 days.

Example: To set this to the maximum value, specify:

var transport = endpointConfiguration.UseTransport<SqsTransport>();
transport.MaxTimeToLive(TimeSpan.FromDays(10));
Large message payloads stored in S3 are never deleted by the receiving endpoint, regardless of whether they were successfully handled. The S3 aging policy controls the deletion of the payload and will respect the configured TTL. Since message payloads stored in S3 are important for audited and failed messages stored in ServiceControl, it is crucial that the ServiceControl message retention period is aligned with the configured SQS and S3 TTL.

QueueNamePrefix

Optional

Default: None

This string value is prepended to the name of every SQS queue referenced by the endpoint. This is useful when deploying many instances of the same application in the same AWS region (e.g. a development instance, a QA instance, and a production instance), and the queue names must be distinguished from each other.

Example: For a development instance, specify:

var transport = endpointConfiguration.UseTransport<SqsTransport>();
transport.QueueNamePrefix("DEV-");

For example, queue names for the endpoint called "SampleEndpoint" might be:

DEV-SampleEndpoint
DEV-SampleEndpoint-Retries
DEV-SampleEndpoint-Timeouts
DEV-SampleEndpoint-TimeoutsDispatcher

S3BucketForLargeMessages

Optional

Default: Empty. Any attempt to send a large message with an empty S3 bucket will fail.

This is the name of an S3 Bucket that will be used to store message bodies for messages larger than 256kB in size. If this option is not specified, S3 will not be used at all. Any attempt to send a message larger than 256kB will throw an exception if a value is not supplied for this parameter.

If the specified bucket doesn't exist, it will be created when the endpoint starts.

Example: To use a bucket named nsb-sqs-messages, specify:

var transport = endpointConfiguration.UseTransport<SqsTransport>();
var s3Configuration = transport.S3(
    bucketForLargeMessages: "nsb-sqs-messages",
    keyPrefix: "my/sample/path");

S3KeyPrefix

Optional

Default: Empty

This is the path within the specified S3 Bucket to store large message bodies. If this option is specified without a value for S3BucketForLargeMessages, an exception will be thrown.

S3 Client Factory

Optional

Default: () => new AmazonS3Client()

This overloads the default S3 client factory with a custom factory creation delegate.

Example: To use a custom factory, specify:

var transport = endpointConfiguration.UseTransport<SqsTransport>();
var s3Configuration = transport.S3(bucketName, keyPrefix);
s3Configuration.ClientFactory(() => new AmazonS3Client(new AmazonS3Config()));

ServerSideEncryption

Optional

Default: Null

Specifies the server-side encryption method and an optional key management service key Id to be used when storing large message bodies on S3. If this option is specified in addition to server-side customer encryption, an exception will be thrown.

var transport = endpointConfiguration.UseTransport<SqsTransport>();
var s3Configuration = transport.S3(bucketName, keyPrefix);
s3Configuration.ServerSideEncryption(ServerSideEncryptionMethod.AES256, keyManagementServiceKeyId: "keyId");

ServerSideCustomerEncryption

Optional

Default: Null

Specifies the server-side customer encryption method, the encryption key and an optional MD5 of the provided key to be used when storing and retrieving large message bodies using S3. If this option is specified with an empty key or in addition to server-side encryption, an exception will be thrown.

var transport = endpointConfiguration.UseTransport<SqsTransport>();
var s3Configuration = transport.S3(bucketName, keyPrefix);
s3Configuration.ServerSideCustomerEncryption(ServerSideEncryptionCustomerMethod.AES256, "key", providedKeyMD5: "keyMD5");

V1 Compatibility Mode

Optional

Default: Disabled

This option enables serialization of the TimeToBeReceived and ReplyToAddress message headers in the message envelope for compatibility with endpoints using version 1 of the transport.

This feature is available in version 3.3.0 and later versions of the transport.

Example: To enable version 1 compatibility, specify:

var transport = endpointConfiguration.UseTransport<SqsTransport>();
transport.EnableV1CompatibilityMode();

Unrestricted Delayed Delivery

Optional

Default: disabled

SQS supports delaying message delivery by up to 15 minutes natively. To delay messages longer than 15 minutes, the unrestricted delayed delivery mode has to be enabled.

Example

var transport = endpointConfiguration.UseTransport<SqsTransport>();
transport.UnrestrictedDurationDelayedDelivery();

For a detailed overview about the unrestricted delayed delivery feature, refer to the delayed delivery documentation.

TopicNamePrefix

Optional

Default: None

This string value is prepended to the name of every SNS topic subscribed by the endpoint. This is useful when deploying many instances of the same application in the same AWS region (e.g. a development instance, a QA instance, and a production instance), and the topic names must be distinguished from each other.

Example: For a development instance, specify:

var transport = endpointConfiguration.UseTransport<SqsTransport>();
transport.TopicNamePrefix("DEV-");

For example, topic names for the topic called "MyNameSpace.MyEvent" might be:

DEV-MyNameSpace-MyEvent

TopicNameGenerator

Optional

Default: $"{topicNamePrefix}{eventType.FullName} with unsupported characters like . being replaced with a hyphen -

Provides the ability to override the topic name generation with a custom function that allows creating topics in alignment with custom conventions.

var transport = endpointConfiguration.UseTransport<SqsTransport>();
transport.TopicNameGenerator((eventType, topicNamePrefix) => $"{topicNamePrefix}{eventType.Name}");

Be aware that ServiceControl doesn't allow customization of this convention when publishing ServiceControl events. ServiceControl events will be published using the default naming convention.

Custom topics mappings

The transport topology describes in depth how the topology is determined by subscribers. There are scenarios in which a custom mapping is needed.

The MapEvent transport configuration API can be used to customize the way subscribers determine the topic to subscribe to. If the subscribers have knowledge of both the published event type and the subscribed one, the following API can be used:

var transport = endpointConfiguration.UseTransport<SqsTransport>();
transport.MapEvent<SubscribedEvent, PublishedEvent>();
The types are only used to determine the topic name; subscribers can define dummy empty types to use the strongly typed API shown above.

If the published type is not known at compilation time, the following API can be used:

var transport = endpointConfiguration.UseTransport<SqsTransport>();
transport.MapEvent<SubscribedEvent>("topic-used-by-the-publisher");

Message driven pub/sub compatibility mode

To gradually move an existing system from message driven pub/sub to native pub/sub using SNS, it's possible to enable message-driven pub/sub compatibility mode.

Message-driven pub/sub compatibility mode must be enabled on publisher endpoints. When enabled, publishers will still consume subscription messages sent by endpoints using message-driven pub/sub, and when publishing an event, it will be published both to legacy subscribers and to SNS. Publishers deduplicate published events.

To enable message-driven Pub/Sub compatibility mode, configure the endpoint as follows:

var transport = endpointConfiguration.UseTransport<SqsTransport>();
transport.EnableMessageDrivenPubSubCompatibilityMode();

Last modified