Skip to content

Commit

Permalink
feat: add support for .NET SDK V4 (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
96malhar authored Oct 25, 2024
1 parent 83d0a8c commit 5e80982
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 39 deletions.
25 changes: 25 additions & 0 deletions .autover/changes/477dcfa7-055f-4342-8633-de16951d29c1.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
]
}
4 changes: 2 additions & 2 deletions src/AWS.Messaging.Lambda/AWS.Messaging.Lambda.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<WarningsAsErrors>CA1727</WarningsAsErrors>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\public.snk</AssemblyOriginatorKeyFile>
<Version>0.10.0</Version>
<Version>2.0.0-preview.1</Version>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
Expand All @@ -26,7 +26,7 @@
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.2.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ public async Task DeleteMessagesAsync(IEnumerable<MessageEnvelope> messages, Can

var request = new DeleteMessageBatchRequest
{
QueueUrl = _configuration.SubscriberEndpoint
QueueUrl = _configuration.SubscriberEndpoint,
Entries = new List<DeleteMessageBatchRequestEntry>()
};

foreach (var message in messages)
Expand All @@ -246,12 +247,15 @@ public async Task DeleteMessagesAsync(IEnumerable<MessageEnvelope> messages, Can

var response = await _sqsClient.DeleteMessageBatchAsync(request, token);

foreach (var successMessage in response.Successful)
var successFulResponse = response.Successful ?? new List<DeleteMessageBatchResultEntry>();
var failedResponse = response.Failed ?? new List<BatchResultErrorEntry>();

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<WarningsAsErrors>CA1727</WarningsAsErrors>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\public.snk</AssemblyOriginatorKeyFile>
<Version>0.9.1</Version>
<Version>2.0.0-preview.1</Version>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
Expand All @@ -28,7 +28,7 @@
<ItemGroup>
<PackageReference Include="OpenTelemetry" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Api" Version="1.6.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions src/AWS.Messaging/AWS.Messaging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@
<WarningsAsErrors>CA1727</WarningsAsErrors>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\public.snk</AssemblyOriginatorKeyFile>
<Version>0.9.2</Version>
<Version>2.0.0-preview.1</Version>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.EventBridge" Version="3.7.302.40" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.300" />
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.7.301.22" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.300.74" />
<PackageReference Include="AWSSDK.EventBridge" Version="4.0.0-preview.4" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="4.0.0-preview.4" />
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="4.0.0-preview.4" />
<PackageReference Include="AWSSDK.SQS" Version="4.0.0-preview.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.*" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 17 additions & 8 deletions src/AWS.Messaging/SQS/SQSMessagePoller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private async Task PollQueue(CancellationToken token)
VisibilityTimeout = _configuration.VisibilityTimeout,
WaitTimeSeconds = _configuration.WaitTimeSeconds,
MaxNumberOfMessages = numberOfMessagesToRead,
AttributeNames = new List<string> { "All" },
MessageSystemAttributeNames = new List<string> { "All" },
MessageAttributeNames = new List<string> { "All" }
};

Expand Down Expand Up @@ -214,7 +214,8 @@ public async Task DeleteMessagesAsync(IEnumerable<MessageEnvelope> messages, Can

var request = new DeleteMessageBatchRequest
{
QueueUrl = _configuration.SubscriberEndpoint
QueueUrl = _configuration.SubscriberEndpoint,
Entries = new List<DeleteMessageBatchRequestEntry>()
};

foreach (var message in messages)
Expand All @@ -240,12 +241,15 @@ public async Task DeleteMessagesAsync(IEnumerable<MessageEnvelope> messages, Can
{
var response = await _sqsClient.DeleteMessageBatchAsync(request, token);

foreach (var successMessage in response.Successful)
var successfulResponses = response.Successful ?? new List<DeleteMessageBatchResultEntry>();
var failedResponses = response.Failed ?? new List<BatchResultErrorEntry>();

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);
Expand Down Expand Up @@ -286,7 +290,8 @@ public async Task ExtendMessageVisibilityTimeoutAsync(IEnumerable<MessageEnvelop

var currentRequest = new ChangeMessageVisibilityBatchRequest
{
QueueUrl = _configuration.SubscriberEndpoint
QueueUrl = _configuration.SubscriberEndpoint,
Entries = new List<ChangeMessageVisibilityBatchRequestEntry>()
};
foreach (var message in messages)
{
Expand All @@ -300,7 +305,8 @@ public async Task ExtendMessageVisibilityTimeoutAsync(IEnumerable<MessageEnvelop
requestBatches.Add(currentRequest);
currentRequest = new ChangeMessageVisibilityBatchRequest
{
QueueUrl = _configuration.SubscriberEndpoint
QueueUrl = _configuration.SubscriberEndpoint,
Entries = new List<ChangeMessageVisibilityBatchRequestEntry>()
};
}
currentRequest.Entries.Add(new ChangeMessageVisibilityBatchRequestEntry
Expand Down Expand Up @@ -338,12 +344,15 @@ public async Task ExtendMessageVisibilityTimeoutAsync(IEnumerable<MessageEnvelop
if (!changeMessageVisibilityBatchTask.IsFaulted)
{
var response = changeMessageVisibilityBatchTask.Result;
foreach (var successMessage in response.Successful)
var successFulResonses = response.Successful ?? new List<ChangeMessageVisibilityBatchResultEntry>();
var failedResponses = response.Failed ?? new List<BatchResultErrorEntry>();

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
Expand Down
4 changes: 4 additions & 0 deletions src/AWS.Messaging/Serialization/EnvelopeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.305.15" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.301" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.305.6" />
<PackageReference Include="AWSSDK.S3" Version="3.7.307.15" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.300.75" />
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="4.0.0-preview.4" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="4.0.0-preview.4" />
<PackageReference Include="AWSSDK.Lambda" Version="4.0.0-preview.4" />
<PackageReference Include="AWSSDK.S3" Version="4.0.0-preview.4" />
<PackageReference Include="AWSSDK.SecurityToken" Version="4.0.0-preview.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.*" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.300" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.300.74" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="4.0.0-preview.4" />
<PackageReference Include="AWSSDK.SQS" Version="4.0.0-preview.4" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.305.15" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.301" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.305.6" />
<PackageReference Include="AWSSDK.S3" Version="3.7.307.15" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.300.75" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.300.74" />
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="4.0.0-preview.4" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="4.0.0-preview.4" />
<PackageReference Include="AWSSDK.Lambda" Version="4.0.0-preview.4" />
<PackageReference Include="AWSSDK.S3" Version="4.0.0-preview.4" />
<PackageReference Include="AWSSDK.SecurityToken" Version="4.0.0-preview.4" />
<PackageReference Include="AWSSDK.SQS" Version="4.0.0-preview.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.*" />
Expand Down
9 changes: 5 additions & 4 deletions test/AWS.Messaging.UnitTests/MessagePublisherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,10 @@ public async Task EventBridgePublisher_UnhappyPath()
It.IsAny<CancellationToken>()),
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]
Expand Down Expand Up @@ -976,7 +977,7 @@ await messagePublisher.PublishAsync(_chatMessage,
x.PutEventsAsync(
It.Is<PutEventsRequest>(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<CancellationToken>()),
Times.Exactly(1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, MessageAttributeValue>(),
Attributes = new Dictionary<string, string>()
};
sqsMessage.MessageAttributes.Add("attr1", new MessageAttributeValue { DataType = "String", StringValue = "val1" });
sqsMessage.Attributes.Add("MessageGroupId", "group-123");
Expand Down

0 comments on commit 5e80982

Please sign in to comment.