From ce5e49075d3777908d1abc9fc5e25c70bbfb757b Mon Sep 17 00:00:00 2001 From: Malhar Khimsaria Date: Wed, 23 Oct 2024 23:27:07 -0700 Subject: [PATCH 1/2] feat: add support for .NET SDK V4 --- .../477dcfa7-055f-4342-8633-de16951d29c1.json | 25 +++++++++++++++++++ .../AWS.Messaging.Lambda.csproj | 2 +- .../Services/DefaultLambdaMessageProcessor.cs | 10 +++++--- ...S.Messaging.Telemetry.OpenTelemetry.csproj | 2 +- src/AWS.Messaging/AWS.Messaging.csproj | 10 ++++---- src/AWS.Messaging/SQS/SQSMessagePoller.cs | 25 +++++++++++++------ .../Serialization/EnvelopeSerializer.cs | 4 +++ .../AWS.Messaging.IntegrationTests.csproj | 14 +++++------ .../AWS.Messaging.Tests.Common.csproj | 12 ++++----- .../MessagePublisherTests.cs | 9 ++++--- .../EnvelopeSerializerTests.cs | 4 ++- 11 files changed, 81 insertions(+), 36 deletions(-) create mode 100644 .autover/changes/477dcfa7-055f-4342-8633-de16951d29c1.json diff --git a/.autover/changes/477dcfa7-055f-4342-8633-de16951d29c1.json b/.autover/changes/477dcfa7-055f-4342-8633-de16951d29c1.json new file mode 100644 index 00000000..ed48df0c --- /dev/null +++ b/.autover/changes/477dcfa7-055f-4342-8633-de16951d29c1.json @@ -0,0 +1,25 @@ +{ + "Projects": [ + { + "Name": "AWS.Messaging", + "Type": "Major", + "ChangelogMessages": [ + "Updated the .NET SDK dependencies to the latest version 4.0.0-preview.4" + ] + }, + { + "Name": "AWS.Messaging.Lambda", + "Type": "Major", + "ChangelogMessages": [ + "Updated the .NET SDK dependencies to the latest version 4.0.0-preview.4" + ] + }, + { + "Name": "AWS.Messaging.Telemetry.OpenTelemetry", + "Type": "Major", + "ChangelogMessages": [ + "Updated the .NET SDK dependencies to the latest version 4.0.0-preview.4" + ] + } + ] +} \ No newline at end of file diff --git a/src/AWS.Messaging.Lambda/AWS.Messaging.Lambda.csproj b/src/AWS.Messaging.Lambda/AWS.Messaging.Lambda.csproj index 862bb725..875d314e 100644 --- a/src/AWS.Messaging.Lambda/AWS.Messaging.Lambda.csproj +++ b/src/AWS.Messaging.Lambda/AWS.Messaging.Lambda.csproj @@ -16,7 +16,7 @@ CA1727 true ..\..\public.snk - 0.10.0 + 2.0.0-preview.1 true true true diff --git a/src/AWS.Messaging.Lambda/Services/DefaultLambdaMessageProcessor.cs b/src/AWS.Messaging.Lambda/Services/DefaultLambdaMessageProcessor.cs index 0062a145..673a7b85 100644 --- a/src/AWS.Messaging.Lambda/Services/DefaultLambdaMessageProcessor.cs +++ b/src/AWS.Messaging.Lambda/Services/DefaultLambdaMessageProcessor.cs @@ -222,7 +222,8 @@ public async Task DeleteMessagesAsync(IEnumerable messages, Can var request = new DeleteMessageBatchRequest { - QueueUrl = _configuration.SubscriberEndpoint + QueueUrl = _configuration.SubscriberEndpoint, + Entries = new List() }; foreach (var message in messages) @@ -246,12 +247,15 @@ public async Task DeleteMessagesAsync(IEnumerable messages, Can var response = await _sqsClient.DeleteMessageBatchAsync(request, token); - foreach (var successMessage in response.Successful) + var successFulResponse = response.Successful ?? new List(); + var failedResponse = response.Failed ?? new List(); + + foreach (var successMessage in successFulResponse) { _logger.LogTrace("Deleted message {MessageId} from queue {SubscriberEndpoint} successfully", successMessage.Id, _configuration.SubscriberEndpoint); } - foreach (var failedMessage in response.Failed) + foreach (var failedMessage in failedResponse) { _logger.LogError("Failed to delete message {FailedMessageId} from queue {SubscriberEndpoint}: {FailedMessage}", failedMessage.Id, _configuration.SubscriberEndpoint, failedMessage.Message); diff --git a/src/AWS.Messaging.Telemetry.OpenTelemetry/AWS.Messaging.Telemetry.OpenTelemetry.csproj b/src/AWS.Messaging.Telemetry.OpenTelemetry/AWS.Messaging.Telemetry.OpenTelemetry.csproj index 769297ca..acb98896 100644 --- a/src/AWS.Messaging.Telemetry.OpenTelemetry/AWS.Messaging.Telemetry.OpenTelemetry.csproj +++ b/src/AWS.Messaging.Telemetry.OpenTelemetry/AWS.Messaging.Telemetry.OpenTelemetry.csproj @@ -18,7 +18,7 @@ CA1727 true ..\..\public.snk - 0.9.1 + 2.0.0-preview.1 true true true diff --git a/src/AWS.Messaging/AWS.Messaging.csproj b/src/AWS.Messaging/AWS.Messaging.csproj index 6086a143..2ca160c0 100644 --- a/src/AWS.Messaging/AWS.Messaging.csproj +++ b/src/AWS.Messaging/AWS.Messaging.csproj @@ -17,7 +17,7 @@ CA1727 true ..\..\public.snk - 0.9.2 + 2.0.0-preview.1 true true true @@ -25,10 +25,10 @@ - - - - + + + + diff --git a/src/AWS.Messaging/SQS/SQSMessagePoller.cs b/src/AWS.Messaging/SQS/SQSMessagePoller.cs index 63800803..5b1ad215 100644 --- a/src/AWS.Messaging/SQS/SQSMessagePoller.cs +++ b/src/AWS.Messaging/SQS/SQSMessagePoller.cs @@ -107,7 +107,7 @@ private async Task PollQueue(CancellationToken token) VisibilityTimeout = _configuration.VisibilityTimeout, WaitTimeSeconds = _configuration.WaitTimeSeconds, MaxNumberOfMessages = numberOfMessagesToRead, - AttributeNames = new List { "All" }, + MessageSystemAttributeNames = new List { "All" }, MessageAttributeNames = new List { "All" } }; @@ -214,7 +214,8 @@ public async Task DeleteMessagesAsync(IEnumerable messages, Can var request = new DeleteMessageBatchRequest { - QueueUrl = _configuration.SubscriberEndpoint + QueueUrl = _configuration.SubscriberEndpoint, + Entries = new List() }; foreach (var message in messages) @@ -240,12 +241,15 @@ public async Task DeleteMessagesAsync(IEnumerable messages, Can { var response = await _sqsClient.DeleteMessageBatchAsync(request, token); - foreach (var successMessage in response.Successful) + var successfulResponses = response.Successful ?? new List(); + var failedResponses = response.Failed ?? new List(); + + foreach (var successMessage in successfulResponses) { _logger.LogTrace("Deleted message {MessageId} from queue {SubscriberEndpoint} successfully", successMessage.Id, _configuration.SubscriberEndpoint); } - foreach (var failedMessage in response.Failed) + foreach (var failedMessage in failedResponses) { _logger.LogError("Failed to delete message {FailedMessageId} from queue {SubscriberEndpoint}: {FailedMessage}", failedMessage.Id, _configuration.SubscriberEndpoint, failedMessage.Message); @@ -286,7 +290,8 @@ public async Task ExtendMessageVisibilityTimeoutAsync(IEnumerable() }; foreach (var message in messages) { @@ -300,7 +305,8 @@ public async Task ExtendMessageVisibilityTimeoutAsync(IEnumerable() }; } currentRequest.Entries.Add(new ChangeMessageVisibilityBatchRequestEntry @@ -338,12 +344,15 @@ public async Task ExtendMessageVisibilityTimeoutAsync(IEnumerable(); + var failedResponses = response.Failed ?? new List(); + + foreach (var successMessage in successFulResonses) { _logger.LogTrace("Extended the visibility of message {MessageId} on queue {SubscriberEndpoint} successfully", successMessage.Id, _configuration.SubscriberEndpoint); } - foreach (var failedMessage in response.Failed) + foreach (var failedMessage in failedResponses) { // It's possible that the task that is extending the message visibility timeout of in flight messages attempts to extend // a message whose handler task has just finished and deleted the message. Rather than adding synchronization between the two diff --git a/src/AWS.Messaging/Serialization/EnvelopeSerializer.cs b/src/AWS.Messaging/Serialization/EnvelopeSerializer.cs index ddc304d2..d95ec198 100644 --- a/src/AWS.Messaging/Serialization/EnvelopeSerializer.cs +++ b/src/AWS.Messaging/Serialization/EnvelopeSerializer.cs @@ -272,6 +272,10 @@ private void SetSQSMetadata(MessageEnvelopeConfiguration envelopeConfiguration, MessageAttributes = sqsMessage.MessageAttributes, ReceiptHandle = sqsMessage.ReceiptHandle }; + if (sqsMessage.Attributes is null || sqsMessage.Attributes.Count == 0) + { + return; + } if (sqsMessage.Attributes.TryGetValue("MessageGroupId", out var attribute)) { envelopeConfiguration.SQSMetadata.MessageGroupId = attribute; diff --git a/test/AWS.Messaging.IntegrationTests/AWS.Messaging.IntegrationTests.csproj b/test/AWS.Messaging.IntegrationTests/AWS.Messaging.IntegrationTests.csproj index c7674d63..fe1f1bb0 100644 --- a/test/AWS.Messaging.IntegrationTests/AWS.Messaging.IntegrationTests.csproj +++ b/test/AWS.Messaging.IntegrationTests/AWS.Messaging.IntegrationTests.csproj @@ -9,16 +9,16 @@ - - - - - + + + + + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/AWS.Messaging.Tests.Common/AWS.Messaging.Tests.Common.csproj b/test/AWS.Messaging.Tests.Common/AWS.Messaging.Tests.Common.csproj index cab70e2d..fd696290 100644 --- a/test/AWS.Messaging.Tests.Common/AWS.Messaging.Tests.Common.csproj +++ b/test/AWS.Messaging.Tests.Common/AWS.Messaging.Tests.Common.csproj @@ -9,12 +9,12 @@ - - - - - - + + + + + + diff --git a/test/AWS.Messaging.UnitTests/MessagePublisherTests.cs b/test/AWS.Messaging.UnitTests/MessagePublisherTests.cs index ca9e9d6b..7b1a8030 100644 --- a/test/AWS.Messaging.UnitTests/MessagePublisherTests.cs +++ b/test/AWS.Messaging.UnitTests/MessagePublisherTests.cs @@ -774,9 +774,10 @@ public async Task EventBridgePublisher_UnhappyPath() It.IsAny()), Times.Exactly(1)); - Assert.Equal("Message failed to publish.", publishResponse.Result.Message); - Assert.Equal("ErrorMessage", publishResponse.Result.InnerException.Message); - Assert.Equal("ErrorCode", ((EventBridgePutEventsException)publishResponse.Result.InnerException).ErrorCode); + var publishResponseResult = await publishResponse; + Assert.Equal("Message failed to publish.", publishResponseResult.Message); + Assert.Equal("ErrorMessage", publishResponseResult.InnerException!.Message); + Assert.Equal("ErrorCode", ((EventBridgePutEventsException)publishResponseResult.InnerException).ErrorCode); } [Fact] @@ -976,7 +977,7 @@ await messagePublisher.PublishAsync(_chatMessage, x.PutEventsAsync( It.Is(request => request.Entries[0].EventBusName.Equals("event-bus-123") && string.IsNullOrEmpty(request.EndpointId) - && request.Entries[0].TraceHeader.Equals("trace-header1") && request.Entries[0].Time.Year == dateTimeOffset.Year), + && request.Entries[0].TraceHeader.Equals("trace-header1") && ((DateTime)request.Entries[0].Time!).Year == dateTimeOffset.Year), It.IsAny()), Times.Exactly(1)); } diff --git a/test/AWS.Messaging.UnitTests/SerializationTests/EnvelopeSerializerTests.cs b/test/AWS.Messaging.UnitTests/SerializationTests/EnvelopeSerializerTests.cs index 254d9f6a..b1462474 100644 --- a/test/AWS.Messaging.UnitTests/SerializationTests/EnvelopeSerializerTests.cs +++ b/test/AWS.Messaging.UnitTests/SerializationTests/EnvelopeSerializerTests.cs @@ -145,7 +145,9 @@ public async Task ConvertToEnvelope_NoOuterEnvelope_In_SQSMessageBody() var sqsMessage = new Message { Body = await envelopeSerializer.SerializeAsync(messageEnvelope), - ReceiptHandle = "receipt-handle" + ReceiptHandle = "receipt-handle", + MessageAttributes = new Dictionary(), + Attributes = new Dictionary() }; sqsMessage.MessageAttributes.Add("attr1", new MessageAttributeValue { DataType = "String", StringValue = "val1" }); sqsMessage.Attributes.Add("MessageGroupId", "group-123"); From e2c269719a1948da947f275e7e318288fb0466d0 Mon Sep 17 00:00:00 2001 From: Malhar Khimsaria Date: Thu, 24 Oct 2024 10:27:42 -0700 Subject: [PATCH 2/2] Update Microsoft.SourceLink.GitHub to 8.0.0 --- src/AWS.Messaging.Lambda/AWS.Messaging.Lambda.csproj | 2 +- .../AWS.Messaging.Telemetry.OpenTelemetry.csproj | 2 +- src/AWS.Messaging/AWS.Messaging.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AWS.Messaging.Lambda/AWS.Messaging.Lambda.csproj b/src/AWS.Messaging.Lambda/AWS.Messaging.Lambda.csproj index 875d314e..4fd5c16f 100644 --- a/src/AWS.Messaging.Lambda/AWS.Messaging.Lambda.csproj +++ b/src/AWS.Messaging.Lambda/AWS.Messaging.Lambda.csproj @@ -26,7 +26,7 @@ - + diff --git a/src/AWS.Messaging.Telemetry.OpenTelemetry/AWS.Messaging.Telemetry.OpenTelemetry.csproj b/src/AWS.Messaging.Telemetry.OpenTelemetry/AWS.Messaging.Telemetry.OpenTelemetry.csproj index acb98896..286a843e 100644 --- a/src/AWS.Messaging.Telemetry.OpenTelemetry/AWS.Messaging.Telemetry.OpenTelemetry.csproj +++ b/src/AWS.Messaging.Telemetry.OpenTelemetry/AWS.Messaging.Telemetry.OpenTelemetry.csproj @@ -28,7 +28,7 @@ - + diff --git a/src/AWS.Messaging/AWS.Messaging.csproj b/src/AWS.Messaging/AWS.Messaging.csproj index 2ca160c0..3f9327be 100644 --- a/src/AWS.Messaging/AWS.Messaging.csproj +++ b/src/AWS.Messaging/AWS.Messaging.csproj @@ -34,7 +34,7 @@ - +