From e001a262f3bb69ce674b97263c9f8c554c5ca7ef Mon Sep 17 00:00:00 2001 From: kentdr Date: Mon, 21 Aug 2023 11:01:13 -0400 Subject: [PATCH 01/31] Bump major version --- src/Custom.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Custom.Build.props b/src/Custom.Build.props index 3b7e325..ac8e9cb 100644 --- a/src/Custom.Build.props +++ b/src/Custom.Build.props @@ -6,7 +6,7 @@ - 1.0 + 2.0 minor From 10714df71b9e6998f921a634e757381bb0d69461 Mon Sep 17 00:00:00 2001 From: kentdr Date: Mon, 21 Aug 2023 14:37:49 -0400 Subject: [PATCH 02/31] Update TFMs for net8.0 and remove if defs --- .../NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj | 2 +- .../NServiceBus.AwsLambda.SQS.Tests.csproj | 2 +- .../NServiceBus.AwsLambda.SQS.csproj | 2 +- src/NServiceBus.AwsLambda.SQS/TransportMessage.cs | 4 ---- src/NServiceBus.AwsLambda.SQS/TransportMessageExtensions.cs | 1 - 5 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj index c0fe736..d94c6b6 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0 + net8.0 true NServiceBus.AcceptanceTests diff --git a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj index 2ff208b..3426e77 100644 --- a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0 + net8.0 true NServiceBus.AwsLambda.Tests diff --git a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj index a99ab42..b31ff9e 100644 --- a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj +++ b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0 + net8.0 true ..\NServiceBus.snk diff --git a/src/NServiceBus.AwsLambda.SQS/TransportMessage.cs b/src/NServiceBus.AwsLambda.SQS/TransportMessage.cs index b38de6e..1d054dd 100644 --- a/src/NServiceBus.AwsLambda.SQS/TransportMessage.cs +++ b/src/NServiceBus.AwsLambda.SQS/TransportMessage.cs @@ -32,11 +32,7 @@ public TransportMessage(OutgoingMessage outgoingMessage, DispatchProperties prop if (outgoingMessage.Body.Length != 0) { -#if NETFRAMEWORK - Body = Convert.ToBase64String(outgoingMessage.Body.ToArray()); -#else Body = Convert.ToBase64String(outgoingMessage.Body.Span); -#endif } else { diff --git a/src/NServiceBus.AwsLambda.SQS/TransportMessageExtensions.cs b/src/NServiceBus.AwsLambda.SQS/TransportMessageExtensions.cs index 5f033f1..0e5c2b8 100644 --- a/src/NServiceBus.AwsLambda.SQS/TransportMessageExtensions.cs +++ b/src/NServiceBus.AwsLambda.SQS/TransportMessageExtensions.cs @@ -4,7 +4,6 @@ namespace NServiceBus.AwsLambda.SQS using System; using System.Buffers; using System.IO; - using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; From 3f4858d73c70f1f3f65a9978bd809aa5e87ce8a9 Mon Sep 17 00:00:00 2001 From: kentdr Date: Mon, 21 Aug 2023 14:40:28 -0400 Subject: [PATCH 03/31] Update workflows --- .github/workflows/ci.yml | 11 +++++------ .github/workflows/release.yml | 9 +++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2296b2..b247df7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,9 +19,9 @@ jobs: strategy: matrix: include: - - os: windows-2019 + - os: windows-2022 name: Windows - - os: ubuntu-20.04 + - os: ubuntu-22.04 name: Linux fail-fast: false steps: @@ -33,13 +33,12 @@ jobs: - name: Checkout uses: actions/checkout@v4.1.1 with: - fetch-depth: 0 + fetch-depth: 0 - name: Setup .NET SDK uses: actions/setup-dotnet@v4.0.0 with: - dotnet-version: | - 7.0.x - 6.0.x + dotnet-version: 8.0.x + dotnet-quality: 'preview' - name: Build run: dotnet build src --configuration Release - name: Upload packages diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 334f60b..4b845ba 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,16 +8,17 @@ env: DOTNET_NOLOGO: true jobs: release: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v4.1.1 with: - fetch-depth: 0 + fetch-depth: 0 - name: Setup .NET SDK uses: actions/setup-dotnet@v4.0.0 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x + dotnet-quality: 'preview' - name: Build run: dotnet build src --configuration Release - name: Sign NuGet packages @@ -36,4 +37,4 @@ jobs: - name: Deploy uses: Particular/push-octopus-package-action@v1.2.1 with: - octopus-deploy-api-key: ${{ secrets.OCTOPUS_DEPLOY_API_KEY }} \ No newline at end of file + octopus-deploy-api-key: ${{ secrets.OCTOPUS_DEPLOY_API_KEY }} From fa9114a135229dee51c1fdd3fb5fbece2c9f96d6 Mon Sep 17 00:00:00 2001 From: kentdr Date: Fri, 25 Aug 2023 11:34:40 -0400 Subject: [PATCH 04/31] Update Test SDK and GitHubActionsLogger --- .../NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj | 2 +- .../NServiceBus.AwsLambda.SQS.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj index d94c6b6..f7fcf24 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj @@ -1,4 +1,4 @@ - + net8.0 diff --git a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj index 3426e77..9720919 100644 --- a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj @@ -1,4 +1,4 @@ - + net8.0 From dd2276b024df469a6980a95508ba2e8a931a2ba5 Mon Sep 17 00:00:00 2001 From: kentdr Date: Fri, 25 Aug 2023 14:55:30 -0400 Subject: [PATCH 05/31] Bump NServiceBus.AmazonSQS --- src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml | 3 +++ .../NServiceBus.AwsLambda.SQS.csproj | 3 ++- .../TransportWrapper/ServerlessTransport.cs | 15 +-------------- src/NServiceBus.AwsLambda.SQS/obsoletes-v2.cs | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml create mode 100644 src/NServiceBus.AwsLambda.SQS/obsoletes-v2.cs diff --git a/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml b/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml new file mode 100644 index 0000000..4d5e3e3 --- /dev/null +++ b/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj index b31ff9e..55b6073 100644 --- a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj +++ b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj @@ -13,7 +13,8 @@ - + + diff --git a/src/NServiceBus.AwsLambda.SQS/TransportWrapper/ServerlessTransport.cs b/src/NServiceBus.AwsLambda.SQS/TransportWrapper/ServerlessTransport.cs index 2d4dc56..a10b5d5 100644 --- a/src/NServiceBus.AwsLambda.SQS/TransportWrapper/ServerlessTransport.cs +++ b/src/NServiceBus.AwsLambda.SQS/TransportWrapper/ServerlessTransport.cs @@ -6,7 +6,7 @@ using NServiceBus; using Transport; - sealed class ServerlessTransport : TransportDefinition + sealed partial class ServerlessTransport : TransportDefinition { ServerlessTransportInfrastructure serverlessTransportInfrastructure; @@ -28,19 +28,6 @@ public override async Task Initialize(HostSettings host return serverlessTransportInfrastructure; } - public ServerlessTransportInfrastructure GetTransportInfrastructure(IEndpointInstance _) => - // IEndpointInstance is only required to guarantee that GetTransportInfrastructure can't be called before NServiceBus called Initialize. - serverlessTransportInfrastructure; - -#pragma warning disable CS0672 // Member overrides obsolete member -#pragma warning disable CS0618 // Type or member is obsolete - - public override string ToTransportAddress(QueueAddress address) => BaseTransport.ToTransportAddress(address); - -#pragma warning restore CS0618 // Type or member is obsolete -#pragma warning restore CS0672 // Member overrides obsolete member - - public override IReadOnlyCollection GetSupportedTransactionModes() => supportedTransactionModes; readonly TransportTransactionMode[] supportedTransactionModes = diff --git a/src/NServiceBus.AwsLambda.SQS/obsoletes-v2.cs b/src/NServiceBus.AwsLambda.SQS/obsoletes-v2.cs new file mode 100644 index 0000000..44ecd91 --- /dev/null +++ b/src/NServiceBus.AwsLambda.SQS/obsoletes-v2.cs @@ -0,0 +1,17 @@ +namespace NServiceBus.AwsLambda.SQS.TransportWrapper +{ + using System; + using NServiceBus.Transport; + + sealed partial class ServerlessTransport + { +#pragma warning disable CS0672 // Member overrides obsolete member + + [ObsoleteEx(Message = "Inject the ITransportAddressResolver type to access the address translation mechanism at runtime. See the NServiceBus version 8 upgrade guide for further details.", + TreatAsErrorFromVersion = "2", + RemoveInVersion = "3")] + public override string ToTransportAddress(QueueAddress address) => throw new NotImplementedException(); + +#pragma warning restore CS0672 // Member overrides obsolete member + } +} From 0d175b4a7a14a03d364d08d5ceed64b736b37367 Mon Sep 17 00:00:00 2001 From: kentdr Date: Fri, 25 Aug 2023 16:39:47 -0400 Subject: [PATCH 06/31] Adjust FodyWeavers.xml --- src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml b/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml index 4d5e3e3..6d8cf1b 100644 --- a/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml +++ b/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml @@ -1,3 +1,4 @@ - + + - \ No newline at end of file + From eefdffcbaf59ded3058c195d8524e4043318d181 Mon Sep 17 00:00:00 2001 From: kentdr Date: Mon, 25 Sep 2023 10:52:57 -0400 Subject: [PATCH 07/31] Update TFM on Analyzer project --- .../NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj index 6d7c357..fe170d8 100644 --- a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0 + net8.0 true ..\NServiceBusTests.snk @@ -19,5 +19,5 @@ - + From 7d8976d936e58795570af1ebab985d1146392aa3 Mon Sep 17 00:00:00 2001 From: kentdr Date: Mon, 25 Sep 2023 10:53:26 -0400 Subject: [PATCH 08/31] Fix collection intialization error --- .../AwsLambdaSQSEndpointTestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs index 356a8f8..73f66df 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs @@ -40,7 +40,7 @@ class AwsLambdaSQSEndpointTestBase [SetUp] public async Task Setup() { - queueNames = new List(); + queueNames = []; Prefix = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()).ToLowerInvariant(); From 428c2092ef1a91b3bb544195c643de8b67fca6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Thu, 29 Feb 2024 09:55:34 +0100 Subject: [PATCH 09/31] Tweaks --- .github/workflows/ci.yml | 3 +- .github/workflows/release.yml | 1 - .../.editorconfig | 1 + .../AwsLambdaSQSEndpointTestBase.cs | 12 +- ...ceBus.AwsLambda.SQS.AcceptanceTests.csproj | 13 +- .../ReceiveMessageResponseExtensions.cs | 3 +- .../AnalyzerTestFixture.cs | 6 +- ...iceBus.AwsLambda.SQS.Analyzer.Tests.csproj | 6 +- .../NServiceBus.AwsLambda.SQS.Analyzer.csproj | 9 +- .../NServiceBus.AwsLambda.SQS.Tests.csproj | 15 ++- .../AwsLambdaEndpoint.cs | 115 +++++++++--------- .../IAwsLambdaSQSEndpoint.cs | 24 ++-- .../NServiceBus.AwsLambda.SQS.csproj | 10 +- .../SQSEventExtensions.cs | 5 +- .../TransportWrapper/IMessageProcessor.cs | 5 +- .../TransportWrapper/PipelineInvoker.cs | 4 +- .../SendOnlyMessageProcessor.cs | 5 +- src/NServiceBus.AwsLambda.Sqs.sln | 2 + 18 files changed, 133 insertions(+), 106 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b247df7..d88e3e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ env: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} NSERVICEBUS_AMAZONSQS_S3BUCKET: ${{ secrets.NSERVICEBUS_AMAZONSQS_S3BUCKET }} jobs: - build: + build: name: ${{ matrix.name }} runs-on: ${{ matrix.os }} strategy: @@ -38,7 +38,6 @@ jobs: uses: actions/setup-dotnet@v4.0.0 with: dotnet-version: 8.0.x - dotnet-quality: 'preview' - name: Build run: dotnet build src --configuration Release - name: Upload packages diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4b845ba..60a0b61 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,6 @@ jobs: uses: actions/setup-dotnet@v4.0.0 with: dotnet-version: 8.0.x - dotnet-quality: 'preview' - name: Build run: dotnet build src --configuration Release - name: Sign NuGet packages diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/.editorconfig b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/.editorconfig index 0f61b0e..7efe105 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/.editorconfig +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/.editorconfig @@ -2,6 +2,7 @@ # Justification: Test project dotnet_diagnostic.CA2007.severity = none +dotnet_diagnostic.PS0018.severity = none # Justification: Tests don't support cancellation and don't need to forward IMessageHandlerContext.CancellationToken dotnet_diagnostic.NSB0002.severity = suggestion diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs index 73f66df..683a627 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs @@ -156,8 +156,8 @@ protected void RegisterQueueNameToCleanup(string queueName) { MaxNumberOfMessages = count, WaitTimeSeconds = 20, - AttributeNames = new List { "SentTimestamp" }, - MessageAttributeNames = new List { "*" } + AttributeNames = ["SentTimestamp"], + MessageAttributeNames = ["*"] }; var receivedMessages = await sqsClient.ReceiveMessageAsync(receiveRequest); @@ -183,8 +183,8 @@ await sqsClient.SendMessageAsync(sendMessageRequest) { MaxNumberOfMessages = 10, WaitTimeSeconds = 20, - AttributeNames = new List { "SentTimestamp" }, - MessageAttributeNames = new List { "*" } + AttributeNames = ["SentTimestamp"], + MessageAttributeNames = ["*"] }; var receivedMessages = await sqsClient.ReceiveMessageAsync(receiveRequest); @@ -214,8 +214,8 @@ protected async Task RetrieveMessagesInErrorQueue(int maxMessageCount { MaxNumberOfMessages = maxMessageCount, WaitTimeSeconds = 20, - AttributeNames = new List { "SentTimestamp" }, - MessageAttributeNames = new List { "*" } + AttributeNames = ["SentTimestamp"], + MessageAttributeNames = ["*"] }; var receivedMessages = await sqsClient.ReceiveMessageAsync(receiveRequest); diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj index f7fcf24..7f320b3 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj @@ -7,14 +7,21 @@ - + + + + - - + + + + + + diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/ReceiveMessageResponseExtensions.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/ReceiveMessageResponseExtensions.cs index a510479..3ff1ed6 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/ReceiveMessageResponseExtensions.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/ReceiveMessageResponseExtensions.cs @@ -1,6 +1,5 @@ namespace NServiceBus.AcceptanceTests { - using System.Collections.Generic; using Amazon.Lambda.SQSEvents; using Amazon.SQS.Model; @@ -10,7 +9,7 @@ public static SQSEvent ToSQSEvent(this ReceiveMessageResponse response) { var @event = new SQSEvent { - Records = new List() + Records = [] }; foreach (var message in response.Messages) { diff --git a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/AnalyzerTestFixture.cs b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/AnalyzerTestFixture.cs index 181b8d2..dd2ca68 100644 --- a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/AnalyzerTestFixture.cs +++ b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/AnalyzerTestFixture.cs @@ -29,7 +29,7 @@ protected async Task Assert(string[] expectedDiagnosticIds, string markupCode, s var (code, markupSpans) = Parse(markupCode); var project = CreateProject(code); - await WriteCode(project); + await WriteCode(project, cancellationToken); var compilerDiagnostics = (await Task.WhenAll(project.Documents .Select(doc => doc.GetCompilerDiagnostics(cancellationToken)))) @@ -58,7 +58,7 @@ protected async Task Assert(string[] expectedDiagnosticIds, string markupCode, s NUnit.Framework.CollectionAssert.AreEqual(expectedSpansAndIds, actualSpansAndIds); } - protected static async Task WriteCode(Project project) + protected static async Task WriteCode(Project project, CancellationToken cancellationToken = default) { if (!VerboseLogging) { @@ -68,7 +68,7 @@ protected static async Task WriteCode(Project project) foreach (var document in project.Documents) { Console.WriteLine(document.Name); - var code = await document.GetCode(); + var code = await document.GetCode(cancellationToken); foreach (var (line, index) in code.Replace("\r\n", "\n").Split('\n') .Select((line, index) => (line, index))) { diff --git a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj index fe170d8..f366b53 100644 --- a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -20,4 +20,8 @@ + + + + diff --git a/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj b/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj index af24890..716d261 100644 --- a/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj @@ -7,12 +7,17 @@ ..\NServiceBus.snk false false + true - + + + + + @@ -20,4 +25,4 @@ $(MinVerMajor).$(MinVerMinor).$(MinVerPatch).0 - + \ No newline at end of file diff --git a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj index 9720919..0a91a81 100644 --- a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj @@ -7,14 +7,17 @@ - + + + + - - + + - + @@ -22,4 +25,8 @@ + + + + diff --git a/src/NServiceBus.AwsLambda.SQS/AwsLambdaEndpoint.cs b/src/NServiceBus.AwsLambda.SQS/AwsLambdaEndpoint.cs index 7101540..87bbb71 100644 --- a/src/NServiceBus.AwsLambda.SQS/AwsLambdaEndpoint.cs +++ b/src/NServiceBus.AwsLambda.SQS/AwsLambdaEndpoint.cs @@ -57,11 +57,11 @@ await Task.WhenAll(processTasks) .ConfigureAwait(false); } - async Task InitializeEndpointIfNecessary(ILambdaContext executionContext, CancellationToken token = default) + async Task InitializeEndpointIfNecessary(ILambdaContext executionContext, CancellationToken cancellationToken) { if (pipeline == null) { - await semaphoreLock.WaitAsync(token) + await semaphoreLock.WaitAsync(cancellationToken) .ConfigureAwait(false); try { @@ -105,114 +105,114 @@ async Task Initialize(ILambdaContext executio } /// - public async Task Send(object message, SendOptions options, ILambdaContext lambdaContext) + public async Task Send(object message, SendOptions options, ILambdaContext lambdaContext, CancellationToken cancellationToken = default) { - await InitializeEndpointIfNecessary(lambdaContext).ConfigureAwait(false); + await InitializeEndpointIfNecessary(lambdaContext, cancellationToken).ConfigureAwait(false); - await endpoint.Send(message, options).ConfigureAwait(false); + await endpoint.Send(message, options, cancellationToken).ConfigureAwait(false); } /// - public Task Send(object message, ILambdaContext lambdaContext) - => Send(message, new SendOptions(), lambdaContext); + public Task Send(object message, ILambdaContext lambdaContext, CancellationToken cancellationToken = default) + => Send(message, new SendOptions(), lambdaContext, cancellationToken); /// - public async Task Send(Action messageConstructor, SendOptions options, ILambdaContext lambdaContext) + public async Task Send(Action messageConstructor, SendOptions options, ILambdaContext lambdaContext, CancellationToken cancellationToken = default) { - await InitializeEndpointIfNecessary(lambdaContext) + await InitializeEndpointIfNecessary(lambdaContext, cancellationToken) .ConfigureAwait(false); - await endpoint.Send(messageConstructor, options) + await endpoint.Send(messageConstructor, options, cancellationToken) .ConfigureAwait(false); } /// - public async Task Send(Action messageConstructor, ILambdaContext lambdaContext) + public async Task Send(Action messageConstructor, ILambdaContext lambdaContext, CancellationToken cancellationToken = default) { - await InitializeEndpointIfNecessary(lambdaContext) + await InitializeEndpointIfNecessary(lambdaContext, cancellationToken) .ConfigureAwait(false); - await Send(messageConstructor, new SendOptions(), lambdaContext) + await Send(messageConstructor, new SendOptions(), lambdaContext, cancellationToken) .ConfigureAwait(false); } /// - public async Task Publish(object message, PublishOptions options, ILambdaContext lambdaContext) + public async Task Publish(object message, PublishOptions options, ILambdaContext lambdaContext, CancellationToken cancellationToken = default) { - await InitializeEndpointIfNecessary(lambdaContext) + await InitializeEndpointIfNecessary(lambdaContext, cancellationToken) .ConfigureAwait(false); - await endpoint.Publish(message, options) + await endpoint.Publish(message, options, cancellationToken) .ConfigureAwait(false); } /// - public async Task Publish(Action messageConstructor, PublishOptions options, ILambdaContext lambdaContext) + public async Task Publish(Action messageConstructor, PublishOptions options, ILambdaContext lambdaContext, CancellationToken cancellationToken = default) { - await InitializeEndpointIfNecessary(lambdaContext) + await InitializeEndpointIfNecessary(lambdaContext, cancellationToken) .ConfigureAwait(false); - await endpoint.Publish(messageConstructor, options) + await endpoint.Publish(messageConstructor, options, cancellationToken) .ConfigureAwait(false); } /// - public async Task Publish(object message, ILambdaContext lambdaContext) + public async Task Publish(object message, ILambdaContext lambdaContext, CancellationToken cancellationToken = default) { - await InitializeEndpointIfNecessary(lambdaContext) + await InitializeEndpointIfNecessary(lambdaContext, cancellationToken) .ConfigureAwait(false); - await endpoint.Publish(message) + await endpoint.Publish(message, cancellationToken) .ConfigureAwait(false); } /// - public async Task Publish(Action messageConstructor, ILambdaContext lambdaContext) + public async Task Publish(Action messageConstructor, ILambdaContext lambdaContext, CancellationToken cancellationToken = default) { - await InitializeEndpointIfNecessary(lambdaContext) + await InitializeEndpointIfNecessary(lambdaContext, cancellationToken) .ConfigureAwait(false); - await endpoint.Publish(messageConstructor) + await endpoint.Publish(messageConstructor, cancellationToken) .ConfigureAwait(false); } /// - public async Task Subscribe(Type eventType, SubscribeOptions options, ILambdaContext lambdaContext) + public async Task Subscribe(Type eventType, SubscribeOptions options, ILambdaContext lambdaContext, CancellationToken cancellationToken = default) { - await InitializeEndpointIfNecessary(lambdaContext) + await InitializeEndpointIfNecessary(lambdaContext, cancellationToken) .ConfigureAwait(false); - await endpoint.Subscribe(eventType, options) + await endpoint.Subscribe(eventType, options, cancellationToken) .ConfigureAwait(false); } /// - public async Task Subscribe(Type eventType, ILambdaContext lambdaContext) + public async Task Subscribe(Type eventType, ILambdaContext lambdaContext, CancellationToken cancellationToken = default) { - await InitializeEndpointIfNecessary(lambdaContext) + await InitializeEndpointIfNecessary(lambdaContext, cancellationToken) .ConfigureAwait(false); - await endpoint.Subscribe(eventType) + await endpoint.Subscribe(eventType, cancellationToken) .ConfigureAwait(false); } /// - public async Task Unsubscribe(Type eventType, UnsubscribeOptions options, ILambdaContext lambdaContext) + public async Task Unsubscribe(Type eventType, UnsubscribeOptions options, ILambdaContext lambdaContext, CancellationToken cancellationToken = default) { - await InitializeEndpointIfNecessary(lambdaContext) + await InitializeEndpointIfNecessary(lambdaContext, cancellationToken) .ConfigureAwait(false); - await endpoint.Unsubscribe(eventType, options) + await endpoint.Unsubscribe(eventType, options, cancellationToken) .ConfigureAwait(false); } /// - public async Task Unsubscribe(Type eventType, ILambdaContext lambdaContext) + public async Task Unsubscribe(Type eventType, ILambdaContext lambdaContext, CancellationToken cancellationToken = default) { - await InitializeEndpointIfNecessary(lambdaContext) + await InitializeEndpointIfNecessary(lambdaContext, cancellationToken) .ConfigureAwait(false); - await endpoint.Unsubscribe(eventType) + await endpoint.Unsubscribe(eventType, cancellationToken) .ConfigureAwait(false); } @@ -222,14 +222,14 @@ async Task GetQueueUrl(string queueName) { return (await sqsClient.GetQueueUrlAsync(queueName).ConfigureAwait(false)).QueueUrl; } - catch (Exception e) + catch (Exception ex) when (!ex.IsCausedBy(cancellationToken)) { Logger.Error($"Failed to obtain the queue URL for queue {queueName} (derived from configured name {queueName}).", e); throw; } } - async Task ProcessMessage(SQSEvent.SQSMessage receivedLambdaMessage, ILambdaContext lambdaContext, CancellationToken token) + async Task ProcessMessage(SQSEvent.SQSMessage receivedLambdaMessage, ILambdaContext lambdaContext, CancellationToken cancellationToken) { var arrayPool = ArrayPool.Shared; ReadOnlyMemory messageBody = null; @@ -258,7 +258,7 @@ async Task ProcessMessage(SQSEvent.SQSMessage receivedLambdaMessage, ILambdaCont { transportMessage = new TransportMessage { - Headers = JsonSerializer.Deserialize>(headersAttribute.StringValue) ?? new Dictionary(), + Headers = JsonSerializer.Deserialize>(headersAttribute.StringValue) ?? [], Body = receivedMessage.Body }; transportMessage.Headers[Headers.MessageId] = messageId; @@ -303,9 +303,9 @@ async Task ProcessMessage(SQSEvent.SQSMessage receivedLambdaMessage, ILambdaCont } } - (messageBody, messageBodyBuffer) = await transportMessage.RetrieveBody(messageId, s3Settings, arrayPool, token).ConfigureAwait(false); + (messageBody, messageBodyBuffer) = await transportMessage.RetrieveBody(messageId, s3Settings, arrayPool, cancellationToken).ConfigureAwait(false); } - catch (Exception ex) when (!ex.IsCausedBy(token)) + catch (Exception ex) when (!ex.IsCausedBy(cancellationToken)) { // Can't deserialize. This is a poison message exception = ex; @@ -316,20 +316,20 @@ async Task ProcessMessage(SQSEvent.SQSMessage receivedLambdaMessage, ILambdaCont { LogPoisonMessage(messageId, exception); - await MovePoisonMessageToErrorQueue(receivedMessage, token).ConfigureAwait(false); + await MovePoisonMessageToErrorQueue(receivedMessage, cancellationToken).ConfigureAwait(false); return; } if (!IsMessageExpired(receivedMessage, transportMessage.Headers, messageId, sqsClient.Config.ClockOffset)) { // here we also want to use the native message id because the core demands it like that - await ProcessMessageWithInMemoryRetries(transportMessage.Headers, nativeMessageId, messageBody, receivedMessage, receivedLambdaMessage, lambdaContext, token).ConfigureAwait(false); + await ProcessMessageWithInMemoryRetries(transportMessage.Headers, nativeMessageId, messageBody, receivedMessage, receivedLambdaMessage, lambdaContext, cancellationToken).ConfigureAwait(false); } // Always delete the message from the queue. // If processing failed, the onError handler will have moved the message // to a retry queue. - await DeleteMessageAndBodyIfRequired(receivedMessage, transportMessage.S3BodyKey).ConfigureAwait(false); + await DeleteMessageAndBodyIfRequired(receivedMessage, transportMessage.S3BodyKey, cancellationToken).ConfigureAwait(false); } finally { @@ -367,7 +367,7 @@ static bool IsMessageExpired(Message receivedMessage, Dictionary return true; } - async Task ProcessMessageWithInMemoryRetries(Dictionary headers, string nativeMessageId, ReadOnlyMemory body, Message nativeMessage, SQSEvent.SQSMessage nativeLambdaMessage, ILambdaContext lambdaContext, CancellationToken token) + async Task ProcessMessageWithInMemoryRetries(Dictionary headers, string nativeMessageId, ReadOnlyMemory body, Message nativeMessage, SQSEvent.SQSMessage nativeLambdaMessage, ILambdaContext lambdaContext, CancellationToken cancellationToken) { var immediateProcessingAttempts = 0; var errorHandled = false; @@ -387,7 +387,7 @@ async Task ProcessMessageWithInMemoryRetries(Dictionary headers, try { - token.ThrowIfCancellationRequested(); + cancellationToken.ThrowIfCancellationRequested(); var messageContext = new MessageContext( nativeMessageId, @@ -397,12 +397,11 @@ async Task ProcessMessageWithInMemoryRetries(Dictionary headers, receiveQueueAddress, context); - await Process(messageContext, lambdaContext, token).ConfigureAwait(false); + await Process(messageContext, lambdaContext, cancellationToken).ConfigureAwait(false); return; } - catch (Exception ex) - when (!(ex is OperationCanceledException && token.IsCancellationRequested)) + catch (Exception ex) when (!ex.IsCausedBy(cancellationToken)) { immediateProcessingAttempts++; ErrorHandleResult errorHandlerResult; @@ -419,9 +418,9 @@ async Task ProcessMessageWithInMemoryRetries(Dictionary headers, receiveQueueAddress, context); - errorHandlerResult = await ProcessFailedMessage(errorContext, lambdaContext).ConfigureAwait(false); + errorHandlerResult = await ProcessFailedMessage(errorContext, lambdaContext, cancellationToken).ConfigureAwait(false); } - catch (Exception onErrorEx) + catch (Exception onErrorEx) when (!onErrorEx.IsCausedBy(cancellationToken)) { Logger.Warn($"Failed to execute recoverability policy for message with native ID: `{nativeMessageId}`", onErrorEx); throw; @@ -436,20 +435,20 @@ async Task Process(MessageContext messageContext, ILambdaContext executionContex { await InitializeEndpointIfNecessary(executionContext, cancellationToken) .ConfigureAwait(false); - await pipeline.PushMessage(messageContext) + await pipeline.PushMessage(messageContext, cancellationToken) .ConfigureAwait(false); } - async Task ProcessFailedMessage(ErrorContext errorContext, ILambdaContext executionContext) + async Task ProcessFailedMessage(ErrorContext errorContext, ILambdaContext executionContext, CancellationToken cancellationToken) { - await InitializeEndpointIfNecessary(executionContext) + await InitializeEndpointIfNecessary(executionContext, cancellationToken) .ConfigureAwait(false); - return await pipeline.PushFailedMessage(errorContext) + return await pipeline.PushFailedMessage(errorContext, cancellationToken) .ConfigureAwait(false); } - async Task DeleteMessageAndBodyIfRequired(Message message, string messageS3BodyKey) + async Task DeleteMessageAndBodyIfRequired(Message message, string messageS3BodyKey, CancellationToken cancellationToken) { try { @@ -488,7 +487,7 @@ await sqsClient.SendMessageAsync(new SendMessageRequest // and can't be re-sent. Unfortunately all the SQS metadata // such as SentTimestamp is reset with this send. } - catch (Exception ex) + catch (Exception ex) when (!ex.IsCausedBy(cancellationToken)) { Logger.Error($"Error moving poison message to error queue at url {errorQueueUrl}. Moving back to input queue.", ex); try diff --git a/src/NServiceBus.AwsLambda.SQS/IAwsLambdaSQSEndpoint.cs b/src/NServiceBus.AwsLambda.SQS/IAwsLambdaSQSEndpoint.cs index 0b82815..13ce351 100644 --- a/src/NServiceBus.AwsLambda.SQS/IAwsLambdaSQSEndpoint.cs +++ b/src/NServiceBus.AwsLambda.SQS/IAwsLambdaSQSEndpoint.cs @@ -20,64 +20,64 @@ public interface IAwsLambdaSQSEndpoint /// /// Sends the provided message. /// - Task Send(object message, SendOptions options, ILambdaContext lambdaContext); + Task Send(object message, SendOptions options, ILambdaContext lambdaContext, CancellationToken cancellationToken = default); /// /// Sends the provided message. /// - Task Send(object message, ILambdaContext lambdaContext); + Task Send(object message, ILambdaContext lambdaContext, CancellationToken cancellationToken = default); /// /// Instantiates a message of type T and sends it. /// - Task Send(Action messageConstructor, SendOptions options, ILambdaContext lambdaContext); + Task Send(Action messageConstructor, SendOptions options, ILambdaContext lambdaContext, CancellationToken cancellationToken = default); /// /// Instantiates a message of type T and sends it. /// - Task Send(Action messageConstructor, ILambdaContext lambdaContext); + Task Send(Action messageConstructor, ILambdaContext lambdaContext, CancellationToken cancellationToken = default); /// /// Publish the message to subscribers. /// - Task Publish(object message, PublishOptions options, ILambdaContext lambdaContext); + Task Publish(object message, PublishOptions options, ILambdaContext lambdaContext, CancellationToken cancellationToken = default); /// /// Instantiates a message of type T and publishes it. /// - Task Publish(Action messageConstructor, PublishOptions options, ILambdaContext lambdaContext); + Task Publish(Action messageConstructor, PublishOptions options, ILambdaContext lambdaContext, CancellationToken cancellationToken = default); /// /// Instantiates a message of type T and publishes it. /// - Task Publish(object message, ILambdaContext lambdaContext); + Task Publish(object message, ILambdaContext lambdaContext, CancellationToken cancellationToken = default); /// /// Instantiates a message of type T and publishes it. /// - Task Publish(Action messageConstructor, ILambdaContext lambdaContext); + Task Publish(Action messageConstructor, ILambdaContext lambdaContext, CancellationToken cancellationToken = default); /// /// Subscribes to receive published messages of the specified type. /// This method is only necessary if you turned off auto-subscribe. /// - Task Subscribe(Type eventType, SubscribeOptions options, ILambdaContext lambdaContext); + Task Subscribe(Type eventType, SubscribeOptions options, ILambdaContext lambdaContext, CancellationToken cancellationToken = default); /// /// Subscribes to receive published messages of the specified type. /// This method is only necessary if you turned off auto-subscribe. /// - Task Subscribe(Type eventType, ILambdaContext lambdaContext); + Task Subscribe(Type eventType, ILambdaContext lambdaContext, CancellationToken cancellationToken = default); /// /// Unsubscribes to receive published messages of the specified type. /// - Task Unsubscribe(Type eventType, UnsubscribeOptions options, ILambdaContext lambdaContext); + Task Unsubscribe(Type eventType, UnsubscribeOptions options, ILambdaContext lambdaContext, CancellationToken cancellationToken = default); /// /// Unsubscribes to receive published messages of the specified type. /// - Task Unsubscribe(Type eventType, ILambdaContext lambdaContext); + Task Unsubscribe(Type eventType, ILambdaContext lambdaContext, CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj index 55b6073..b2f9b61 100644 --- a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj +++ b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj @@ -9,13 +9,17 @@ - + - - + + + + + + diff --git a/src/NServiceBus.AwsLambda.SQS/SQSEventExtensions.cs b/src/NServiceBus.AwsLambda.SQS/SQSEventExtensions.cs index 45e1a75..1a2923e 100644 --- a/src/NServiceBus.AwsLambda.SQS/SQSEventExtensions.cs +++ b/src/NServiceBus.AwsLambda.SQS/SQSEventExtensions.cs @@ -1,7 +1,6 @@ namespace NServiceBus.AwsLambda.SQS { using System.Collections.Generic; - using System.IO; using Amazon.SQS.Model; using static Amazon.Lambda.SQSEvents.SQSEvent; @@ -48,8 +47,8 @@ static MessageAttributeValue CopyMessageAttributeValue(MessageAttribute source) target.BinaryValue = source.BinaryValue ?? target.BinaryValue; // The SQS client returns empty lists instead of null - target.StringListValues = source.StringListValues ?? new List(0); - target.BinaryListValues = source.BinaryListValues ?? new List(0); + target.StringListValues = source.StringListValues ?? []; + target.BinaryListValues = source.BinaryListValues ?? []; return target; } diff --git a/src/NServiceBus.AwsLambda.SQS/TransportWrapper/IMessageProcessor.cs b/src/NServiceBus.AwsLambda.SQS/TransportWrapper/IMessageProcessor.cs index 6e004c1..b6412ec 100644 --- a/src/NServiceBus.AwsLambda.SQS/TransportWrapper/IMessageProcessor.cs +++ b/src/NServiceBus.AwsLambda.SQS/TransportWrapper/IMessageProcessor.cs @@ -1,12 +1,13 @@ namespace NServiceBus.AwsLambda.SQS.TransportWrapper { + using System.Threading; using System.Threading.Tasks; using Transport; interface IMessageProcessor { string ReceiveAddress { get; } - Task PushFailedMessage(ErrorContext errorContext); - Task PushMessage(MessageContext messageContext); + Task PushFailedMessage(ErrorContext errorContext, CancellationToken cancellationToken = default); + Task PushMessage(MessageContext messageContext, CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/NServiceBus.AwsLambda.SQS/TransportWrapper/PipelineInvoker.cs b/src/NServiceBus.AwsLambda.SQS/TransportWrapper/PipelineInvoker.cs index 8a9fe14..ae40790 100644 --- a/src/NServiceBus.AwsLambda.SQS/TransportWrapper/PipelineInvoker.cs +++ b/src/NServiceBus.AwsLambda.SQS/TransportWrapper/PipelineInvoker.cs @@ -30,11 +30,11 @@ Task IMessageReceiver.Initialize(PushRuntimeSettings limitations, OnMessage onMe Task IMessageReceiver.StopReceive(CancellationToken cancellationToken) => Task.CompletedTask; - public Task PushFailedMessage(ErrorContext errorContext) => onError(errorContext); + public Task PushFailedMessage(ErrorContext errorContext, CancellationToken cancellationToken = default) => onError(errorContext, cancellationToken); Task IMessageReceiver.ChangeConcurrency(PushRuntimeSettings limitations, CancellationToken cancellationToken) => Task.CompletedTask; - public Task PushMessage(MessageContext messageContext) => onMessage.Invoke(messageContext); + public Task PushMessage(MessageContext messageContext, CancellationToken cancellationToken = default) => onMessage.Invoke(messageContext, cancellationToken); OnMessage onMessage; OnError onError; diff --git a/src/NServiceBus.AwsLambda.SQS/TransportWrapper/SendOnlyMessageProcessor.cs b/src/NServiceBus.AwsLambda.SQS/TransportWrapper/SendOnlyMessageProcessor.cs index 5929d29..186fc1f 100644 --- a/src/NServiceBus.AwsLambda.SQS/TransportWrapper/SendOnlyMessageProcessor.cs +++ b/src/NServiceBus.AwsLambda.SQS/TransportWrapper/SendOnlyMessageProcessor.cs @@ -1,6 +1,7 @@ namespace NServiceBus.AwsLambda.SQS.TransportWrapper { using System; + using System.Threading; using System.Threading.Tasks; using Transport; @@ -8,10 +9,10 @@ class SendOnlyMessageProcessor : IMessageProcessor { public string ReceiveAddress => string.Empty; - public Task PushFailedMessage(ErrorContext errorContext) => throw new InvalidOperationException( + public Task PushFailedMessage(ErrorContext errorContext, CancellationToken cancellationToken = default) => throw new InvalidOperationException( $"This endpoint cannot process messages because it is configured in send-only mode. Remove the '{nameof(EndpointConfiguration)}.{nameof(EndpointConfiguration.SendOnly)}' configuration.'" ); - public Task PushMessage(MessageContext messageContext) => throw new InvalidOperationException( + public Task PushMessage(MessageContext messageContext, CancellationToken cancellationToken = default) => throw new InvalidOperationException( $"This endpoint cannot process messages because it is configured in send-only mode. Remove the '{nameof(EndpointConfiguration)}.{nameof(EndpointConfiguration.SendOnly)}' configuration.'" ); } diff --git a/src/NServiceBus.AwsLambda.Sqs.sln b/src/NServiceBus.AwsLambda.Sqs.sln index 85fe6a1..04db16a 100644 --- a/src/NServiceBus.AwsLambda.Sqs.sln +++ b/src/NServiceBus.AwsLambda.Sqs.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NServiceBus.AwsLambda.SQS.A EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D637E9DB-45CF-400D-BC9B-D2B1BA892ED5}" ProjectSection(SolutionItems) = preProject + ..\.github\workflows\ci.yml = ..\.github\workflows\ci.yml Custom.Build.props = Custom.Build.props + ..\.github\workflows\release.yml = ..\.github\workflows\release.yml EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NServiceBus.AwsLambda.SQS.Analyzer", "NServiceBus.AwsLambda.SQS.Analyzer\NServiceBus.AwsLambda.SQS.Analyzer.csproj", "{F38B0ACB-6689-4F92-A3AC-06FEAD6E96BB}" From f8c242c9b0a25609a53fa59227fa4048b3b556a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Thu, 29 Feb 2024 09:56:36 +0100 Subject: [PATCH 10/31] Update refs --- .../NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj | 4 ++-- .../NServiceBus.AwsLambda.SQS.Tests.csproj | 4 ++-- .../NServiceBus.AwsLambda.SQS.csproj | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj index 7f320b3..424d775 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj index 0a91a81..f4eb795 100644 --- a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj index b2f9b61..1e2e373 100644 --- a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj +++ b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj @@ -11,8 +11,8 @@ - - + + From e65019ea9f9e86243380c24614b569125f4b64e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Thu, 29 Feb 2024 10:50:20 +0100 Subject: [PATCH 11/31] Fixes after rebase --- .../NServiceBus.AwsLambda.SQS.Analyzer.csproj | 2 +- .../AwsLambdaEndpoint.cs | 16 ++++++++-------- .../TransportWrapper/ServerlessTransport.cs | 4 ++++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj b/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj index 716d261..bfca0ed 100644 --- a/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/NServiceBus.AwsLambda.SQS/AwsLambdaEndpoint.cs b/src/NServiceBus.AwsLambda.SQS/AwsLambdaEndpoint.cs index 87bbb71..9262efe 100644 --- a/src/NServiceBus.AwsLambda.SQS/AwsLambdaEndpoint.cs +++ b/src/NServiceBus.AwsLambda.SQS/AwsLambdaEndpoint.cs @@ -67,7 +67,7 @@ await semaphoreLock.WaitAsync(cancellationToken) { if (pipeline == null) { - var transportInfrastructure = await Initialize(executionContext, token).ConfigureAwait(false); + var transportInfrastructure = await Initialize(executionContext, cancellationToken).ConfigureAwait(false); pipeline = transportInfrastructure.PipelineInvoker; } @@ -79,7 +79,7 @@ await semaphoreLock.WaitAsync(cancellationToken) } } - async Task Initialize(ILambdaContext executionContext, CancellationToken token) + async Task Initialize(ILambdaContext executionContext, CancellationToken cancellationToken) { var configuration = configurationFactory(executionContext); @@ -89,7 +89,7 @@ async Task Initialize(ILambdaContext executio var serverlessTransport = new ServerlessTransport(configuration.Transport); configuration.EndpointConfiguration.UseTransport(serverlessTransport); - endpoint = await Endpoint.Start(configuration.EndpointConfiguration, token).ConfigureAwait(false); + endpoint = await Endpoint.Start(configuration.EndpointConfiguration, cancellationToken).ConfigureAwait(false); var transportInfrastructure = serverlessTransport.GetTransportInfrastructure(endpoint); isSendOnly = transportInfrastructure.IsSendOnly; @@ -97,8 +97,8 @@ async Task Initialize(ILambdaContext executio if (!isSendOnly) { receiveQueueAddress = transportInfrastructure.PipelineInvoker.ReceiveAddress; - receiveQueueUrl = await GetQueueUrl(receiveQueueAddress).ConfigureAwait(false); - errorQueueUrl = await GetQueueUrl(transportInfrastructure.ErrorQueueAddress).ConfigureAwait(false); + receiveQueueUrl = await GetQueueUrl(receiveQueueAddress, cancellationToken).ConfigureAwait(false); + errorQueueUrl = await GetQueueUrl(transportInfrastructure.ErrorQueueAddress, cancellationToken).ConfigureAwait(false); } return transportInfrastructure; @@ -216,15 +216,15 @@ await endpoint.Unsubscribe(eventType, cancellationToken) .ConfigureAwait(false); } - async Task GetQueueUrl(string queueName) + async Task GetQueueUrl(string queueName, CancellationToken cancellationToken) { try { - return (await sqsClient.GetQueueUrlAsync(queueName).ConfigureAwait(false)).QueueUrl; + return (await sqsClient.GetQueueUrlAsync(queueName, cancellationToken).ConfigureAwait(false)).QueueUrl; } catch (Exception ex) when (!ex.IsCausedBy(cancellationToken)) { - Logger.Error($"Failed to obtain the queue URL for queue {queueName} (derived from configured name {queueName}).", e); + Logger.Error($"Failed to obtain the queue URL for queue {queueName} (derived from configured name {queueName}).", ex); throw; } } diff --git a/src/NServiceBus.AwsLambda.SQS/TransportWrapper/ServerlessTransport.cs b/src/NServiceBus.AwsLambda.SQS/TransportWrapper/ServerlessTransport.cs index a10b5d5..e2fe777 100644 --- a/src/NServiceBus.AwsLambda.SQS/TransportWrapper/ServerlessTransport.cs +++ b/src/NServiceBus.AwsLambda.SQS/TransportWrapper/ServerlessTransport.cs @@ -28,6 +28,10 @@ public override async Task Initialize(HostSettings host return serverlessTransportInfrastructure; } + public ServerlessTransportInfrastructure GetTransportInfrastructure(IEndpointInstance _) => + // IEndpointInstance is only required to guarantee that GetTransportInfrastructure can't be called before NServiceBus called Initialize. + serverlessTransportInfrastructure; + public override IReadOnlyCollection GetSupportedTransactionModes() => supportedTransactionModes; readonly TransportTransactionMode[] supportedTransactionModes = From 3f549a95360bdef2dfff1e719d90aea766869cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Thu, 29 Feb 2024 11:05:36 +0100 Subject: [PATCH 12/31] Set serializer --- .../AwsLambdaSQSEndpointTestBase.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs index 683a627..31ff3f6 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs @@ -15,7 +15,6 @@ using Amazon.SQS; using Amazon.SQS.Model; using Microsoft.Extensions.DependencyInjection; - using Microsoft.VisualStudio.TestPlatform.ObjectModel; using NUnit.Framework; [TestFixture] @@ -119,7 +118,7 @@ protected AwsLambdaSQSEndpointConfiguration DefaultLambdaEndpointConfiguration() var advanced = configuration.AdvancedConfiguration; advanced.SendFailedMessagesTo(ErrorQueueAddress); - + advanced.UseSerialization(); return configuration; } From c6b35fa1889b0a268f484cdc932cef0d68fc4435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Thu, 29 Feb 2024 11:14:21 +0100 Subject: [PATCH 13/31] Use xml serializer --- .../AwsLambdaSQSEndpointTestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs index 31ff3f6..b5d5219 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs @@ -118,7 +118,7 @@ protected AwsLambdaSQSEndpointConfiguration DefaultLambdaEndpointConfiguration() var advanced = configuration.AdvancedConfiguration; advanced.SendFailedMessagesTo(ErrorQueueAddress); - advanced.UseSerialization(); + advanced.UseSerialization(); return configuration; } From 10bd513897fec3eb254493372703d3162f6fca37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Thu, 29 Feb 2024 13:10:25 +0100 Subject: [PATCH 14/31] Approve api --- .../APIApprovals.Approve.approved.txt | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt b/src/NServiceBus.AwsLambda.SQS.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt index 1adef98..072f6cb 100644 --- a/src/NServiceBus.AwsLambda.SQS.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt +++ b/src/NServiceBus.AwsLambda.SQS.Tests/ApprovalFiles/APIApprovals.Approve.approved.txt @@ -4,18 +4,18 @@ namespace NServiceBus { public AwsLambdaSQSEndpoint(System.Func configurationFactory) { } public System.Threading.Tasks.Task Process(Amazon.Lambda.SQSEvents.SQSEvent @event, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default) { } - public System.Threading.Tasks.Task Publish(object message, Amazon.Lambda.Core.ILambdaContext lambdaContext) { } - public System.Threading.Tasks.Task Publish(object message, NServiceBus.PublishOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext) { } - public System.Threading.Tasks.Task Publish(System.Action messageConstructor, Amazon.Lambda.Core.ILambdaContext lambdaContext) { } - public System.Threading.Tasks.Task Publish(System.Action messageConstructor, NServiceBus.PublishOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext) { } - public System.Threading.Tasks.Task Send(object message, Amazon.Lambda.Core.ILambdaContext lambdaContext) { } - public System.Threading.Tasks.Task Send(object message, NServiceBus.SendOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext) { } - public System.Threading.Tasks.Task Send(System.Action messageConstructor, Amazon.Lambda.Core.ILambdaContext lambdaContext) { } - public System.Threading.Tasks.Task Send(System.Action messageConstructor, NServiceBus.SendOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext) { } - public System.Threading.Tasks.Task Subscribe(System.Type eventType, Amazon.Lambda.Core.ILambdaContext lambdaContext) { } - public System.Threading.Tasks.Task Subscribe(System.Type eventType, NServiceBus.SubscribeOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext) { } - public System.Threading.Tasks.Task Unsubscribe(System.Type eventType, Amazon.Lambda.Core.ILambdaContext lambdaContext) { } - public System.Threading.Tasks.Task Unsubscribe(System.Type eventType, NServiceBus.UnsubscribeOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext) { } + public System.Threading.Tasks.Task Publish(object message, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default) { } + public System.Threading.Tasks.Task Publish(object message, NServiceBus.PublishOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default) { } + public System.Threading.Tasks.Task Publish(System.Action messageConstructor, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default) { } + public System.Threading.Tasks.Task Publish(System.Action messageConstructor, NServiceBus.PublishOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default) { } + public System.Threading.Tasks.Task Send(object message, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default) { } + public System.Threading.Tasks.Task Send(object message, NServiceBus.SendOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default) { } + public System.Threading.Tasks.Task Send(System.Action messageConstructor, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default) { } + public System.Threading.Tasks.Task Send(System.Action messageConstructor, NServiceBus.SendOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default) { } + public System.Threading.Tasks.Task Subscribe(System.Type eventType, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default) { } + public System.Threading.Tasks.Task Subscribe(System.Type eventType, NServiceBus.SubscribeOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default) { } + public System.Threading.Tasks.Task Unsubscribe(System.Type eventType, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default) { } + public System.Threading.Tasks.Task Unsubscribe(System.Type eventType, NServiceBus.UnsubscribeOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default) { } } public class AwsLambdaSQSEndpointConfiguration { @@ -31,17 +31,17 @@ namespace NServiceBus public interface IAwsLambdaSQSEndpoint { System.Threading.Tasks.Task Process(Amazon.Lambda.SQSEvents.SQSEvent @event, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default); - System.Threading.Tasks.Task Publish(object message, Amazon.Lambda.Core.ILambdaContext lambdaContext); - System.Threading.Tasks.Task Publish(object message, NServiceBus.PublishOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext); - System.Threading.Tasks.Task Publish(System.Action messageConstructor, Amazon.Lambda.Core.ILambdaContext lambdaContext); - System.Threading.Tasks.Task Publish(System.Action messageConstructor, NServiceBus.PublishOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext); - System.Threading.Tasks.Task Send(object message, Amazon.Lambda.Core.ILambdaContext lambdaContext); - System.Threading.Tasks.Task Send(object message, NServiceBus.SendOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext); - System.Threading.Tasks.Task Send(System.Action messageConstructor, Amazon.Lambda.Core.ILambdaContext lambdaContext); - System.Threading.Tasks.Task Send(System.Action messageConstructor, NServiceBus.SendOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext); - System.Threading.Tasks.Task Subscribe(System.Type eventType, Amazon.Lambda.Core.ILambdaContext lambdaContext); - System.Threading.Tasks.Task Subscribe(System.Type eventType, NServiceBus.SubscribeOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext); - System.Threading.Tasks.Task Unsubscribe(System.Type eventType, Amazon.Lambda.Core.ILambdaContext lambdaContext); - System.Threading.Tasks.Task Unsubscribe(System.Type eventType, NServiceBus.UnsubscribeOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext); + System.Threading.Tasks.Task Publish(object message, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default); + System.Threading.Tasks.Task Publish(object message, NServiceBus.PublishOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default); + System.Threading.Tasks.Task Publish(System.Action messageConstructor, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default); + System.Threading.Tasks.Task Publish(System.Action messageConstructor, NServiceBus.PublishOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default); + System.Threading.Tasks.Task Send(object message, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default); + System.Threading.Tasks.Task Send(object message, NServiceBus.SendOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default); + System.Threading.Tasks.Task Send(System.Action messageConstructor, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default); + System.Threading.Tasks.Task Send(System.Action messageConstructor, NServiceBus.SendOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default); + System.Threading.Tasks.Task Subscribe(System.Type eventType, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default); + System.Threading.Tasks.Task Subscribe(System.Type eventType, NServiceBus.SubscribeOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default); + System.Threading.Tasks.Task Unsubscribe(System.Type eventType, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default); + System.Threading.Tasks.Task Unsubscribe(System.Type eventType, NServiceBus.UnsubscribeOptions options, Amazon.Lambda.Core.ILambdaContext lambdaContext, System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file From 01a2e73713e2a4042efb3b1070bfd095ab7d38e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Thu, 29 Feb 2024 13:15:17 +0100 Subject: [PATCH 15/31] Set serializer --- .../When_a_handler_sends_a_message.cs | 1 + .../When_using_send_only.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_a_handler_sends_a_message.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_a_handler_sends_a_message.cs index 9d81b06..a54b2ee 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_a_handler_sends_a_message.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_a_handler_sends_a_message.cs @@ -20,6 +20,7 @@ public async Task The_message_should_be_received() var destinationConfiguration = new EndpointConfiguration(destinationEndpointName); + destinationConfiguration.UseSerialization(); destinationConfiguration.SendFailedMessagesTo(ErrorQueueAddress); destinationConfiguration.EnableInstallers(); destinationConfiguration.RegisterComponents(c => c.AddSingleton(typeof(TestContext), context)); diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_using_send_only.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_using_send_only.cs index 6aa548b..21c5851 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_using_send_only.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_using_send_only.cs @@ -36,6 +36,7 @@ public async Task Should_send_messages() var destinationTransport = new SqsTransport(CreateSQSClient(), CreateSNSClient()); destinationConfiguration.SendFailedMessagesTo(ErrorQueueAddress); + destinationConfiguration.UseSerialization(); destinationConfiguration.EnableInstallers(); destinationConfiguration.RegisterComponents(c => c.AddSingleton(typeof(TestContext), context)); destinationConfiguration.UseTransport(destinationTransport); From 8e1419bbf9a29f7ccf87f8179c87484ad9cda9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Thu, 29 Feb 2024 14:08:26 +0100 Subject: [PATCH 16/31] Use xml where needed --- .../AwsLambdaSQSEndpointTestBase.cs | 18 ++++++++++++++---- ...receiving_a_native_message_with_encoding.cs | 10 +++++----- ...ceiving_a_native_message_without_wrapper.cs | 10 +++++----- .../When_message_fails_processing.cs | 3 +-- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs index b5d5219..97918b7 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs @@ -102,14 +102,14 @@ await s3Client.DeleteObjectsAsync(new DeleteObjectsRequest } } - protected AwsLambdaSQSEndpointConfiguration DefaultLambdaEndpointConfiguration(TTestContext testContext) + protected AwsLambdaSQSEndpointConfiguration DefaultLambdaEndpointConfiguration(TTestContext testContext, bool useXmlSerializer = false) { - var configuration = DefaultLambdaEndpointConfiguration(); + var configuration = DefaultLambdaEndpointConfiguration(useXmlSerializer); configuration.AdvancedConfiguration.RegisterComponents(c => c.AddSingleton(typeof(TTestContext), testContext)); return configuration; } - protected AwsLambdaSQSEndpointConfiguration DefaultLambdaEndpointConfiguration() + protected AwsLambdaSQSEndpointConfiguration DefaultLambdaEndpointConfiguration(bool useXmlSerializer = false) { var configuration = new AwsLambdaSQSEndpointConfiguration(QueueName, CreateSQSClient(), CreateSNSClient()); configuration.Transport.QueueNamePrefix = Prefix; @@ -118,7 +118,16 @@ protected AwsLambdaSQSEndpointConfiguration DefaultLambdaEndpointConfiguration() var advanced = configuration.AdvancedConfiguration; advanced.SendFailedMessagesTo(ErrorQueueAddress); - advanced.UseSerialization(); + + if (useXmlSerializer) + { + advanced.UseSerialization(); + } + else + { + advanced.UseSerialization(); + } + return configuration; } @@ -137,6 +146,7 @@ protected void RegisterQueueNameToCleanup(string queueName) S3 = new S3Settings(BucketName, Prefix, CreateS3Client()) }; + endpointConfiguration.UseSerialization(); endpointConfiguration.UseTransport(transport); var endpointInstance = await Endpoint.Start(endpointConfiguration) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_with_encoding.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_with_encoding.cs index e23c1d3..4667811 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_with_encoding.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_with_encoding.cs @@ -24,7 +24,7 @@ public async Task Should_be_processed_when_messagetypefullname_present() var context = new TestContext(); - var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context)); + var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context, useXmlSerializer: true)); await endpoint.Process(receivedMessages, null); @@ -48,7 +48,7 @@ public async Task Should_fail_when_messagetypefullname_not_present() var context = new TestContext(); - var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context)); + var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context, useXmlSerializer: true)); await endpoint.Process(receivedMessages, null); @@ -74,7 +74,7 @@ public async Task Should_preserve_poison_message_attributes_in_error_queue() var context = new TestContext(); - var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context)); + var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context, useXmlSerializer: true)); await endpoint.Process(receivedMessages, null); var poisonMessages = await RetrieveMessagesInErrorQueue(); @@ -105,7 +105,7 @@ public async Task Should_preserve_message_attributes_in_error_queue() var endpoint = new AwsLambdaSQSEndpoint(ctx => { - var configuration = DefaultLambdaEndpointConfiguration(); + var configuration = DefaultLambdaEndpointConfiguration(useXmlSerializer: true); configuration.AdvancedConfiguration.Recoverability().Immediate(s => s.NumberOfRetries(0)); return configuration; }); @@ -139,7 +139,7 @@ public async Task Should_support_loading_body_from_s3() var context = new TestContext(); - var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context)); + var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context, useXmlSerializer: true)); await endpoint.Process(receivedMessages, null); diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_without_wrapper.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_without_wrapper.cs index 50bd597..4d63604 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_without_wrapper.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_without_wrapper.cs @@ -30,7 +30,7 @@ public async Task Should_be_processed_when_nsbheaders_present_with_messageid() var context = new TestContext(); - var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context)); + var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context, useXmlSerializer: true)); await endpoint.Process(receivedMessages, null); @@ -57,7 +57,7 @@ public async Task Should_be_processed_when_nsbheaders_present_without_messageid( var context = new TestContext(); - var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context)); + var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context, useXmlSerializer: true)); await endpoint.Process(receivedMessages, null); @@ -88,7 +88,7 @@ public async Task Should_support_loading_body_from_s3() var context = new TestContext(); - var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context)); + var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(context, useXmlSerializer: true)); await endpoint.Process(receivedMessages, null); @@ -119,7 +119,7 @@ public async Task Should_preserve_poison_message_attributes_in_error_queue() var endpoint = new AwsLambdaSQSEndpoint(ctx => { - var configuration = DefaultLambdaEndpointConfiguration(); + var configuration = DefaultLambdaEndpointConfiguration(useXmlSerializer: true); var transport = configuration.Transport; transport.S3 = new S3Settings(BucketName, Prefix, CreateS3Client()); @@ -162,7 +162,7 @@ public async Task Should_preserve_message_attributes_in_error_queue() var endpoint = new AwsLambdaSQSEndpoint(ctx => { - var configuration = DefaultLambdaEndpointConfiguration(); + var configuration = DefaultLambdaEndpointConfiguration(useXmlSerializer: true); var transport = configuration.Transport; transport.S3 = new S3Settings(BucketName, Prefix, CreateS3Client()); diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs index fe5d665..3d2cd8c 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs @@ -46,8 +46,7 @@ public async Task Should_rethrow_when_disabling_error_queue() var exception = Assert.ThrowsAsync(() => endpoint.Process(receivedMessages, null)); - StringAssert.Contains("Failed to process message", exception.Message); - Assert.AreEqual("simulated exception", exception.InnerException.Message); + Assert.AreEqual("simulated exception", exception.Message); Assert.AreEqual(0, await CountMessagesInErrorQueue()); Assert.AreEqual(6, context.HandlerInvocationCount, "should immediately retry message before moving it to the error queue"); } From 2305c134d0208eae69b844d9bd3af3c6d666297c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Fri, 1 Mar 2024 08:15:26 +0100 Subject: [PATCH 17/31] Tweaks --- src/Custom.Build.props | 2 +- .../NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj | 7 +------ .../NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj | 4 ---- .../NServiceBus.AwsLambda.SQS.Analyzer.csproj | 4 ---- .../NServiceBus.AwsLambda.SQS.Tests.csproj | 10 +--------- .../NServiceBus.AwsLambda.SQS.csproj | 4 ---- 6 files changed, 3 insertions(+), 28 deletions(-) diff --git a/src/Custom.Build.props b/src/Custom.Build.props index ac8e9cb..c951ad2 100644 --- a/src/Custom.Build.props +++ b/src/Custom.Build.props @@ -1,7 +1,7 @@ - 0.9.0 + 1.8.0 netstandard2.0 diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj index 424d775..b8cea9c 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj @@ -2,7 +2,6 @@ net8.0 - true NServiceBus.AcceptanceTests @@ -13,15 +12,11 @@ - + - - - - diff --git a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj index f366b53..50896fd 100644 --- a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/NServiceBus.AwsLambda.SQS.Analyzer.Tests.csproj @@ -20,8 +20,4 @@ - - - - diff --git a/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj b/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj index bfca0ed..f6f1731 100644 --- a/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj @@ -16,10 +16,6 @@ - - - - $(MinVerMajor).$(MinVerMinor).$(MinVerPatch).0 diff --git a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj index f4eb795..4145502 100644 --- a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj @@ -2,7 +2,6 @@ net8.0 - true NServiceBus.AwsLambda.Tests @@ -13,10 +12,7 @@ - - - - + @@ -25,8 +21,4 @@ - - - - diff --git a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj index 1e2e373..26dbc51 100644 --- a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj +++ b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj @@ -18,8 +18,4 @@ - - - - From db3832eb029827be0a756faeb739e35b7f5085bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Mon, 4 Mar 2024 08:19:47 +0100 Subject: [PATCH 18/31] Remove uneeded calls to set error queue --- .../AwsLambdaSQSEndpointTestBase.cs | 1 - .../When_a_handler_sends_a_message.cs | 1 - .../When_using_send_only.cs | 1 - 3 files changed, 3 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs index 97918b7..6c23f7f 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs @@ -117,7 +117,6 @@ protected AwsLambdaSQSEndpointConfiguration DefaultLambdaEndpointConfiguration(b configuration.Transport.S3 = new S3Settings(BucketName, Prefix, CreateS3Client()); var advanced = configuration.AdvancedConfiguration; - advanced.SendFailedMessagesTo(ErrorQueueAddress); if (useXmlSerializer) { diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_a_handler_sends_a_message.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_a_handler_sends_a_message.cs index a54b2ee..b4d821d 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_a_handler_sends_a_message.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_a_handler_sends_a_message.cs @@ -21,7 +21,6 @@ public async Task The_message_should_be_received() var destinationConfiguration = new EndpointConfiguration(destinationEndpointName); destinationConfiguration.UseSerialization(); - destinationConfiguration.SendFailedMessagesTo(ErrorQueueAddress); destinationConfiguration.EnableInstallers(); destinationConfiguration.RegisterComponents(c => c.AddSingleton(typeof(TestContext), context)); destinationConfiguration.UseTransport(new SqsTransport(CreateSQSClient(), CreateSNSClient()) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_using_send_only.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_using_send_only.cs index 21c5851..10828c8 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_using_send_only.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_using_send_only.cs @@ -35,7 +35,6 @@ public async Task Should_send_messages() var destinationTransport = new SqsTransport(CreateSQSClient(), CreateSNSClient()); - destinationConfiguration.SendFailedMessagesTo(ErrorQueueAddress); destinationConfiguration.UseSerialization(); destinationConfiguration.EnableInstallers(); destinationConfiguration.RegisterComponents(c => c.AddSingleton(typeof(TestContext), context)); From 105970e9027bc16981b4829269579974f77a9fcc Mon Sep 17 00:00:00 2001 From: danielmarbach Date: Thu, 22 Feb 2024 16:01:56 +0100 Subject: [PATCH 19/31] Do not disable delayed delivery since currently the FIFO queue is anyway always required by the transport --- .../AwsLambdaSQSEndpointConfiguration.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS/AwsLambdaSQSEndpointConfiguration.cs b/src/NServiceBus.AwsLambda.SQS/AwsLambdaSQSEndpointConfiguration.cs index 72089b7..fa21c3e 100644 --- a/src/NServiceBus.AwsLambda.SQS/AwsLambdaSQSEndpointConfiguration.cs +++ b/src/NServiceBus.AwsLambda.SQS/AwsLambdaSQSEndpointConfiguration.cs @@ -5,7 +5,6 @@ using Amazon.SimpleNotificationService; using Amazon.SQS; using AwsLambda.SQS; - using NServiceBus.Logging; using Serialization; @@ -37,10 +36,7 @@ public AwsLambdaSQSEndpointConfiguration(string endpointName, IAmazonSQS sqsClie recoverabilityPolicy.SendFailedMessagesToErrorQueue = true; - // delayed delivery is disabled by default as the required FIFO queue might not exist - EndpointConfiguration.Recoverability() - .Delayed(c => c.NumberOfRetries(0)) - .CustomPolicy(recoverabilityPolicy.Invoke); + EndpointConfiguration.Recoverability().CustomPolicy(recoverabilityPolicy.Invoke); if (sqsClient is null && snsClient is null) { From db83beb5f8ba695c2c6bed24e60b199ec38748b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Mon, 4 Mar 2024 10:48:56 +0100 Subject: [PATCH 20/31] Adjust tests to handle that delayed retried now are enabled by default --- .../AwsLambdaSQSEndpointTestBase.cs | 5 +++++ .../When_receiving_a_native_message_with_encoding.cs | 7 +------ .../When_receiving_a_native_message_without_wrapper.cs | 2 -- .../When_a_message_handler_always_throws.cs | 2 -- .../When_message_fails_processing.cs | 1 - 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs index 6c23f7f..1fffc22 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/AwsLambdaSQSEndpointTestBase.cs @@ -127,6 +127,11 @@ protected AwsLambdaSQSEndpointConfiguration DefaultLambdaEndpointConfiguration(b advanced.UseSerialization(); } + var recoverability = advanced.Recoverability(); + + recoverability.Immediate(i => i.NumberOfRetries(0)); + recoverability.Delayed(d => d.NumberOfRetries(0)); + return configuration; } diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_with_encoding.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_with_encoding.cs index 4667811..6f0a90d 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_with_encoding.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_with_encoding.cs @@ -103,12 +103,7 @@ public async Task Should_preserve_message_attributes_in_error_queue() }, FailingMessageToSend); - var endpoint = new AwsLambdaSQSEndpoint(ctx => - { - var configuration = DefaultLambdaEndpointConfiguration(useXmlSerializer: true); - configuration.AdvancedConfiguration.Recoverability().Immediate(s => s.NumberOfRetries(0)); - return configuration; - }); + var endpoint = new AwsLambdaSQSEndpoint(_ => DefaultLambdaEndpointConfiguration(useXmlSerializer: true)); await endpoint.Process(receivedMessages, null); var poisonMessages = await RetrieveMessagesInErrorQueue(); diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_without_wrapper.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_without_wrapper.cs index 4d63604..d838b11 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_without_wrapper.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NativeIntegration/When_receiving_a_native_message_without_wrapper.cs @@ -167,8 +167,6 @@ public async Task Should_preserve_message_attributes_in_error_queue() transport.S3 = new S3Settings(BucketName, Prefix, CreateS3Client()); - var advanced = configuration.AdvancedConfiguration; - advanced.Recoverability().Immediate(s => s.NumberOfRetries(0)); return configuration; }); diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_a_message_handler_always_throws.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_a_message_handler_always_throws.cs index 31345ad..b82320e 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_a_message_handler_always_throws.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_a_message_handler_always_throws.cs @@ -21,8 +21,6 @@ public async Task The_messages_should_forward_to_error_queue_by_default() var messagesInErrorQueueCount = await CountMessagesInErrorQueue(); Assert.AreEqual(receivedMessages.Records.Count, messagesInErrorQueueCount, "Error queue count mismatch"); - - Assert.AreEqual(messagesInErrorQueueCount * 6, context.HandlerInvokationCount, "Immediate/Delayed Retry count mismatch"); } public class TestContext diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs index 3d2cd8c..7ac7800 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs @@ -20,7 +20,6 @@ public async Task Should_move_message_to_error_queue() Assert.DoesNotThrowAsync(() => endpoint.Process(receivedMessages, null), "message should be moved to the error queue instead"); - Assert.AreEqual(6, context.HandlerInvocationCount, "should immediately retry message before moving it to the error queue"); var errorMessages = await RetrieveMessagesInErrorQueue(); Assert.AreEqual(1, errorMessages.Records.Count); JsonDocument errorMessage = JsonSerializer.Deserialize(errorMessages.Records.First().Body); From b4645734028f4ba09628eab7ca02abe160f5b197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Mon, 4 Mar 2024 10:53:05 +0100 Subject: [PATCH 21/31] Fix test --- .../When_message_fails_processing.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs index 7ac7800..eeaac4d 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs @@ -47,7 +47,6 @@ public async Task Should_rethrow_when_disabling_error_queue() Assert.AreEqual("simulated exception", exception.Message); Assert.AreEqual(0, await CountMessagesInErrorQueue()); - Assert.AreEqual(6, context.HandlerInvocationCount, "should immediately retry message before moving it to the error queue"); } public class TestContext From c2a75f9cfdd49a9e574453da84cdd34d1dd44518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Mon, 4 Mar 2024 12:33:22 +0100 Subject: [PATCH 22/31] Update refs --- src/Custom.Build.props | 2 +- .../NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj | 2 +- .../NServiceBus.AwsLambda.SQS.Analyzer.csproj | 2 +- .../NServiceBus.AwsLambda.SQS.Tests.csproj | 4 ++-- .../NServiceBus.AwsLambda.SQS.csproj | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Custom.Build.props b/src/Custom.Build.props index c951ad2..e1c1173 100644 --- a/src/Custom.Build.props +++ b/src/Custom.Build.props @@ -1,7 +1,7 @@ - 1.8.0 + 2.0.0 netstandard2.0 diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj index b8cea9c..36f2d3e 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj b/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj index f6f1731..e0b8bfc 100644 --- a/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj index 4145502..a9ce4c7 100644 --- a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj @@ -11,9 +11,9 @@ - + - + diff --git a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj index 26dbc51..1aa6367 100644 --- a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj +++ b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj @@ -15,7 +15,7 @@ - + From 64001e7180d6f61638786524e6527aec45f9a434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96hlund?= Date: Mon, 4 Mar 2024 12:38:19 +0100 Subject: [PATCH 23/31] Remove weavers file --- src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml diff --git a/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml b/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml deleted file mode 100644 index 6d8cf1b..0000000 --- a/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - From 9ba1a3efdad96b58443623f0bc2e833f81651d65 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Mon, 4 Mar 2024 18:25:11 -0500 Subject: [PATCH 24/31] Revert "Remove weavers file" This reverts commit 64001e7180d6f61638786524e6527aec45f9a434. --- src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml diff --git a/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml b/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml new file mode 100644 index 0000000..6d8cf1b --- /dev/null +++ b/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml @@ -0,0 +1,4 @@ + + + + From e77826a755d2a24b9e3d01dfaf205bdbf35c4ebd Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Mon, 4 Mar 2024 18:50:57 -0500 Subject: [PATCH 25/31] Tweaks --- .github/workflows/ci.yml | 1 - src/GuardTemplates.DotSettings | 56 ------------------- ...ceBus.AwsLambda.SQS.AcceptanceTests.csproj | 12 ++-- .../.editorconfig | 4 ++ .../AnalyzerTestFixture.cs | 3 +- .../ConfigurationAnalyzerTests.cs | 8 +-- .../ConfigurationAnalyzerTestsCSharp8.cs | 4 +- .../GlobalSuppressions.cs | 11 ---- ...iceBus.AwsLambda.SQS.Analyzer.Tests.csproj | 15 ++--- .../OptionsAnalyzerTests.cs | 2 +- .../NServiceBus.AwsLambda.SQS.Analyzer.csproj | 7 ++- .../NServiceBus.AwsLambda.SQS.Tests.csproj | 10 ++-- .../NServiceBus.AwsLambda.SQS.csproj | 3 +- 13 files changed, 35 insertions(+), 101 deletions(-) delete mode 100644 src/GuardTemplates.DotSettings create mode 100644 src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/.editorconfig delete mode 100644 src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/GlobalSuppressions.cs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d88e3e9..22dd04e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,4 +49,3 @@ jobs: retention-days: 7 - name: Run tests uses: Particular/run-tests-action@v1.7.0 - diff --git a/src/GuardTemplates.DotSettings b/src/GuardTemplates.DotSettings deleted file mode 100644 index 4352395..0000000 --- a/src/GuardTemplates.DotSettings +++ /dev/null @@ -1,56 +0,0 @@ - - True - guard - Guards against null arguments - Guard.AgainstNull("$ARG$", $ARG$); - True - True - Guard - True - True - InCSharpStatement - 2.0 - True - complete() - 0 - True - guarde - Guards against null or empty arguments - Guard.AgainstNullAndEmpty("$ARG$", $ARG$); - True - True - Guard - True - True - InCSharpStatement - 2.0 - True - complete() - 0 - True - guardn - Guard against negative arguments - Guard.AgainstNegative("$ARG$", $ARG$); - True - True - Guard - True - True - InCSharpStatement - 2.0 - True - 0 - True - guardnz - Guards against negative and zero - Guard.AgainstNegativeAndZero("$ARG$", $ARG$); - True - True - Guard - True - True - InCSharpStatement - 2.0 - True - complete() - 0 \ No newline at end of file diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj index 36f2d3e..b6f9805 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/NServiceBus.AwsLambda.SQS.AcceptanceTests.csproj @@ -2,21 +2,21 @@ net8.0 - NServiceBus.AcceptanceTests + + + + + - + - - - - diff --git a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/.editorconfig b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/.editorconfig new file mode 100644 index 0000000..5f68a61 --- /dev/null +++ b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# Justification: Test project +dotnet_diagnostic.CA2007.severity = none diff --git a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/AnalyzerTestFixture.cs b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/AnalyzerTestFixture.cs index dd2ca68..4921de7 100644 --- a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/AnalyzerTestFixture.cs +++ b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/AnalyzerTestFixture.cs @@ -108,9 +108,8 @@ static AnalyzerTestFixture() MetadataReference.CreateFromFile(typeof(Enumerable).GetTypeInfo().Assembly.Location), MetadataReference.CreateFromFile(typeof(System.Linq.Expressions.Expression).GetTypeInfo().Assembly .Location), -#if NET + MetadataReference.CreateFromFile(Assembly.Load("System.Runtime").Location), -#endif MetadataReference.CreateFromFile(typeof(IAwsLambdaSQSEndpoint).GetTypeInfo().Assembly.Location), MetadataReference.CreateFromFile(typeof(EndpointConfiguration).GetTypeInfo().Assembly.Location), MetadataReference.CreateFromFile(typeof(SqsTransport).GetTypeInfo().Assembly.Location)); diff --git a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/ConfigurationAnalyzerTests.cs b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/ConfigurationAnalyzerTests.cs index 441cdaa..ab74c1c 100644 --- a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/ConfigurationAnalyzerTests.cs +++ b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/ConfigurationAnalyzerTests.cs @@ -17,9 +17,9 @@ public class ConfigurationAnalyzerTests : AnalyzerTestFixture net8.0 - true - ..\NServiceBusTests.snk + + + + + - - + - - - - - diff --git a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/OptionsAnalyzerTests.cs b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/OptionsAnalyzerTests.cs index ac16c70..7f9aed8 100644 --- a/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/OptionsAnalyzerTests.cs +++ b/src/NServiceBus.AwsLambda.SQS.Analyzer.Tests/OptionsAnalyzerTests.cs @@ -13,7 +13,7 @@ public class OptionsAnalyzerTests : AnalyzerTestFixture public Task DiagnosticIsReportedForOptions(string optionsType, string method, string diagnosticId) { var source = - $@"using NServiceBus; + $@"using NServiceBus; class Foo {{ void Bar({optionsType} options) diff --git a/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj b/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj index e0b8bfc..e3a39ce 100644 --- a/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Analyzer/NServiceBus.AwsLambda.SQS.Analyzer.csproj @@ -1,4 +1,4 @@ - + $(AnalyzerTargetFramework) @@ -11,9 +11,9 @@ - - + + @@ -21,4 +21,5 @@ $(MinVerMajor).$(MinVerMinor).$(MinVerPatch).0 + \ No newline at end of file diff --git a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj index a9ce4c7..a2c1dbf 100644 --- a/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj +++ b/src/NServiceBus.AwsLambda.SQS.Tests/NServiceBus.AwsLambda.SQS.Tests.csproj @@ -2,12 +2,16 @@ net8.0 - NServiceBus.AwsLambda.Tests + + + + + @@ -17,8 +21,4 @@ - - - - diff --git a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj index 1aa6367..5632b5e 100644 --- a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj +++ b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj @@ -7,13 +7,14 @@ - + + From c9df1a46829776179af588ff9a97d00d7d6120c5 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Mon, 4 Mar 2024 18:55:47 -0500 Subject: [PATCH 26/31] Address TODO --- .../S3EncryptionMethodExtensions.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS/S3EncryptionMethodExtensions.cs b/src/NServiceBus.AwsLambda.SQS/S3EncryptionMethodExtensions.cs index cbb1ef9..5f6c41b 100644 --- a/src/NServiceBus.AwsLambda.SQS/S3EncryptionMethodExtensions.cs +++ b/src/NServiceBus.AwsLambda.SQS/S3EncryptionMethodExtensions.cs @@ -1,7 +1,7 @@ #nullable enable namespace NServiceBus.AwsLambda.SQS { - using System.Reflection; + using System.Runtime.CompilerServices; using Amazon.S3.Model; static class S3EncryptionMethodExtensions @@ -13,9 +13,10 @@ public static void ModifyRequest(this S3EncryptionMethod encryptionMethod, GetOb return; } - // TODO: Optimize - var methodInfo = encryptionMethod.GetType().GetMethod("ModifyGetRequest", BindingFlags.NonPublic | BindingFlags.Instance); - methodInfo!.Invoke(encryptionMethod, new object?[] { request }); + ModifyGetRequest(encryptionMethod, request); } + + [UnsafeAccessor(UnsafeAccessorKind.Method, Name = "ModifyGetRequest")] + static extern void ModifyGetRequest(S3EncryptionMethod encryptionMethod, GetObjectRequest get); } } \ No newline at end of file From a828331bc73700d2365c989f7c349dfad6166f65 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Mon, 4 Mar 2024 19:09:55 -0500 Subject: [PATCH 27/31] Don't set analyzer version --- src/Custom.Build.props | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Custom.Build.props b/src/Custom.Build.props index e1c1173..de2f7d0 100644 --- a/src/Custom.Build.props +++ b/src/Custom.Build.props @@ -1,7 +1,6 @@ - 2.0.0 netstandard2.0 From 2a77f1e70f4d58fd4827fbe2384b96bf320df180 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Mon, 4 Mar 2024 19:11:55 -0500 Subject: [PATCH 28/31] Remove need for Fody entirely --- src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml | 4 ---- .../NServiceBus.AwsLambda.SQS.csproj | 2 -- .../TransportWrapper/ServerlessTransport.cs | 2 +- src/NServiceBus.AwsLambda.SQS/obsoletes-v2.cs | 17 ----------------- 4 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml delete mode 100644 src/NServiceBus.AwsLambda.SQS/obsoletes-v2.cs diff --git a/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml b/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml deleted file mode 100644 index 6d8cf1b..0000000 --- a/src/NServiceBus.AwsLambda.SQS/FodyWeavers.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj index 5632b5e..0158e75 100644 --- a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj +++ b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj @@ -14,8 +14,6 @@ - - diff --git a/src/NServiceBus.AwsLambda.SQS/TransportWrapper/ServerlessTransport.cs b/src/NServiceBus.AwsLambda.SQS/TransportWrapper/ServerlessTransport.cs index e2fe777..82b8baa 100644 --- a/src/NServiceBus.AwsLambda.SQS/TransportWrapper/ServerlessTransport.cs +++ b/src/NServiceBus.AwsLambda.SQS/TransportWrapper/ServerlessTransport.cs @@ -6,7 +6,7 @@ using NServiceBus; using Transport; - sealed partial class ServerlessTransport : TransportDefinition + sealed class ServerlessTransport : TransportDefinition { ServerlessTransportInfrastructure serverlessTransportInfrastructure; diff --git a/src/NServiceBus.AwsLambda.SQS/obsoletes-v2.cs b/src/NServiceBus.AwsLambda.SQS/obsoletes-v2.cs deleted file mode 100644 index 44ecd91..0000000 --- a/src/NServiceBus.AwsLambda.SQS/obsoletes-v2.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace NServiceBus.AwsLambda.SQS.TransportWrapper -{ - using System; - using NServiceBus.Transport; - - sealed partial class ServerlessTransport - { -#pragma warning disable CS0672 // Member overrides obsolete member - - [ObsoleteEx(Message = "Inject the ITransportAddressResolver type to access the address translation mechanism at runtime. See the NServiceBus version 8 upgrade guide for further details.", - TreatAsErrorFromVersion = "2", - RemoveInVersion = "3")] - public override string ToTransportAddress(QueueAddress address) => throw new NotImplementedException(); - -#pragma warning restore CS0672 // Member overrides obsolete member - } -} From c718da2f092b2a265f13aabae2601d457b830cd3 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Tue, 5 Mar 2024 11:23:59 -0500 Subject: [PATCH 29/31] Fix analyzer project build ordering --- .../NServiceBus.AwsLambda.SQS.csproj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj index 0158e75..42eb757 100644 --- a/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj +++ b/src/NServiceBus.AwsLambda.SQS/NServiceBus.AwsLambda.SQS.csproj @@ -7,7 +7,7 @@ - + @@ -17,4 +17,8 @@ + + + + From efa959ee991989ab06c8d0a078bf359a31db8f4f Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Tue, 5 Mar 2024 13:57:45 -0500 Subject: [PATCH 30/31] Adjust test --- .../When_message_fails_processing.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs index eeaac4d..063e64b 100644 --- a/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs +++ b/src/NServiceBus.AwsLambda.SQS.AcceptanceTests/When_message_fails_processing.cs @@ -1,11 +1,11 @@ namespace NServiceBus.AcceptanceTests { - using NUnit.Framework; - using System.Text.Json; - using System.Threading.Tasks; using System; using System.Linq; + using System.Text.Json; using System.Threading; + using System.Threading.Tasks; + using NUnit.Framework; class When_message_fails_processing : AwsLambdaSQSEndpointTestBase { @@ -45,7 +45,8 @@ public async Task Should_rethrow_when_disabling_error_queue() var exception = Assert.ThrowsAsync(() => endpoint.Process(receivedMessages, null)); - Assert.AreEqual("simulated exception", exception.Message); + StringAssert.Contains("Failed to process message", exception.Message); + Assert.AreEqual("simulated exception", exception.InnerException.Message); Assert.AreEqual(0, await CountMessagesInErrorQueue()); } From 8933c0cfad3b86a47602a3b0920d40bdb27344a5 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Tue, 5 Mar 2024 17:36:26 -0500 Subject: [PATCH 31/31] Move code to avoid throw from nested catch --- .../AwsLambdaEndpoint.cs | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/NServiceBus.AwsLambda.SQS/AwsLambdaEndpoint.cs b/src/NServiceBus.AwsLambda.SQS/AwsLambdaEndpoint.cs index 9262efe..a485831 100644 --- a/src/NServiceBus.AwsLambda.SQS/AwsLambdaEndpoint.cs +++ b/src/NServiceBus.AwsLambda.SQS/AwsLambdaEndpoint.cs @@ -404,27 +404,18 @@ async Task ProcessMessageWithInMemoryRetries(Dictionary headers, catch (Exception ex) when (!ex.IsCausedBy(cancellationToken)) { immediateProcessingAttempts++; - ErrorHandleResult errorHandlerResult; - try - { - var errorContext = new ErrorContext( - ex, - new Dictionary(headers), - nativeMessageId, - body, - transportTransaction, - immediateProcessingAttempts, - receiveQueueAddress, - context); - - errorHandlerResult = await ProcessFailedMessage(errorContext, lambdaContext, cancellationToken).ConfigureAwait(false); - } - catch (Exception onErrorEx) when (!onErrorEx.IsCausedBy(cancellationToken)) - { - Logger.Warn($"Failed to execute recoverability policy for message with native ID: `{nativeMessageId}`", onErrorEx); - throw; - } + var errorContext = new ErrorContext( + ex, + new Dictionary(headers), + nativeMessageId, + body, + transportTransaction, + immediateProcessingAttempts, + receiveQueueAddress, + context); + + var errorHandlerResult = await ProcessFailedMessage(errorContext, lambdaContext, nativeMessageId, cancellationToken).ConfigureAwait(false); errorHandled = errorHandlerResult == ErrorHandleResult.Handled; } @@ -435,17 +426,26 @@ async Task Process(MessageContext messageContext, ILambdaContext executionContex { await InitializeEndpointIfNecessary(executionContext, cancellationToken) .ConfigureAwait(false); + await pipeline.PushMessage(messageContext, cancellationToken) .ConfigureAwait(false); } - async Task ProcessFailedMessage(ErrorContext errorContext, ILambdaContext executionContext, CancellationToken cancellationToken) + async Task ProcessFailedMessage(ErrorContext errorContext, ILambdaContext executionContext, string nativeMessageId, CancellationToken cancellationToken) { - await InitializeEndpointIfNecessary(executionContext, cancellationToken) - .ConfigureAwait(false); + try + { + await InitializeEndpointIfNecessary(executionContext, cancellationToken) + .ConfigureAwait(false); - return await pipeline.PushFailedMessage(errorContext, cancellationToken) - .ConfigureAwait(false); + return await pipeline.PushFailedMessage(errorContext, cancellationToken) + .ConfigureAwait(false); + } + catch (Exception onErrorEx) when (!onErrorEx.IsCausedBy(cancellationToken)) + { + Logger.Warn($"Failed to execute recoverability policy for message with native ID: `{nativeMessageId}`", onErrorEx); + throw; + } } async Task DeleteMessageAndBodyIfRequired(Message message, string messageS3BodyKey, CancellationToken cancellationToken)