Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to disable delayed delivery #2615

Merged
merged 7 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public Task Configure(string endpointName, EndpointConfiguration configuration,

public static SqsTransport PrepareSqsTransport(bool supportsPublishSubscribe = true)
{
var transport = new SqsTransport(ClientFactories.CreateSqsClient(), ClientFactories.CreateSnsClient(), supportsPublishSubscribe)
var transport = new SqsTransport(
ClientFactories.CreateSqsClient(),
ClientFactories.CreateSnsClient(),
supportsPublishSubscribe: supportsPublishSubscribe
)
{
QueueNamePrefix = SetupFixture.NamePrefix,
TopicNamePrefix = SetupFixture.NamePrefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ namespace NServiceBus
{
public SqsTransport() { }
public SqsTransport(Amazon.SQS.IAmazonSQS sqsClient, Amazon.SimpleNotificationService.IAmazonSimpleNotificationService snsClient) { }
[System.Diagnostics.CodeAnalysis.Experimental("NSBSQSEXP0001")]
public SqsTransport(Amazon.SQS.IAmazonSQS sqsClient, Amazon.SimpleNotificationService.IAmazonSimpleNotificationService snsClient, bool enableDelayedDelivery) { }
public bool DoNotWrapOutgoingMessages { get; set; }
[System.Obsolete("The SQS transport no longer supports 1.x compatibility mode. Will be removed in v" +
"ersion 8.0.0.", true)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
static class DiagnosticDescriptors
{
// https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/choosing-diagnostic-ids
public const string ExperimentalDisableDelayedDelivery = "NSBSQSEXP0001";
}
70 changes: 60 additions & 10 deletions src/NServiceBus.Transport.SQS/Configure/SqsTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -57,11 +58,6 @@ internal set
/// </summary>
public string QueueNamePrefix { get; set; }

/// <summary>
/// Disable native delayed delivery infrastructure
/// </summary>
internal bool DisableDelayedDelivery { get; set; } = false;

/// <summary>
/// Specifies a lambda function that allows to take control of the queue name generation logic.
/// This is useful to overcome any limitations imposed by SQS.
Expand Down Expand Up @@ -96,6 +92,7 @@ public TimeSpan MaxTimeToLive
{
throw new ArgumentException($"Max TTL needs to be between {MaxTimeToLiveLowerBound} and {MaxTimeToLiveUpperBound}.");
}

maxTimeToLive = value;
}
}
Expand Down Expand Up @@ -235,8 +232,38 @@ public SqsTransport()
snsClient = DefaultClientFactories.SnsFactory();
}

internal SqsTransport(IAmazonSQS sqsClient, IAmazonSimpleNotificationService snsClient, bool supportsPublishSubscribe)
: base(TransportTransactionMode.ReceiveOnly, true, supportsPublishSubscribe, true)
/// <summary>
/// Creates a new instance of the SQS transport definition.
/// </summary>
[Experimental(DiagnosticDescriptors.ExperimentalDisableDelayedDelivery)]
public SqsTransport(
IAmazonSQS sqsClient,
IAmazonSimpleNotificationService snsClient,
bool enableDelayedDelivery
)
: this(
sqsClient,
snsClient,
supportsPublishSubscribe: true,
enableDelayedDelivery: enableDelayedDelivery
)
{
this.sqsClient = sqsClient;
this.snsClient = snsClient;
}

internal SqsTransport(
IAmazonSQS sqsClient,
IAmazonSimpleNotificationService snsClient,
bool supportsPublishSubscribe,
bool enableDelayedDelivery = true
)
: base(
TransportTransactionMode.ReceiveOnly,
enableDelayedDelivery,
supportsPublishSubscribe,
supportsTTBR: true
)
{
this.sqsClient = sqsClient;
this.snsClient = snsClient;
Expand All @@ -252,15 +279,38 @@ public override async Task<TransportInfrastructure> Initialize(HostSettings host
{
AssertQueueNameGeneratorIdempotent(queueNameGenerator);

var topicCache = new TopicCache(SnsClient, hostSettings.CoreSettings, eventToTopicsMappings, eventToEventsMappings, topicNameGenerator, topicNamePrefix);
var infra = new SqsTransportInfrastructure(hostSettings, receivers, SqsClient, SnsClient, QueueCache, topicCache, S3, Policies, QueueDelayTime, topicNamePrefix, DoNotWrapOutgoingMessages, !externallyManagedSqsClient, !externallyManagedSnsClient, DisableDelayedDelivery);
var topicCache = new TopicCache(
SnsClient,
hostSettings.CoreSettings,
eventToTopicsMappings,
eventToEventsMappings,
topicNameGenerator,
topicNamePrefix
);

var infra = new SqsTransportInfrastructure(
hostSettings,
receivers,
SqsClient,
SnsClient,
QueueCache,
topicCache,
S3,
Policies,
QueueDelayTime,
topicNamePrefix,
DoNotWrapOutgoingMessages,
!externallyManagedSqsClient,
!externallyManagedSnsClient,
!SupportsDelayedDelivery
);

if (hostSettings.SetupInfrastructure)
{
var queueCreator = new QueueCreator(SqsClient, QueueCache, S3, maxTimeToLive, QueueDelayTime);

var createQueueTasks = sendingAddresses.Select(x => queueCreator.CreateQueueIfNecessary(x, false, cancellationToken))
.Concat(infra.Receivers.Values.Select(x => queueCreator.CreateQueueIfNecessary(x.ReceiveAddress, !DisableDelayedDelivery, cancellationToken))).ToArray();
.Concat(infra.Receivers.Values.Select(x => queueCreator.CreateQueueIfNecessary(x.ReceiveAddress, SupportsDelayedDelivery, cancellationToken))).ToArray();

await Task.WhenAll(createQueueTasks).ConfigureAwait(false);
}
Expand Down