Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add support for .NET SDK V4 #163

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
96malhar marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"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"
]
}
]
}
2 changes: 1 addition & 1 deletion 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>
96malhar marked this conversation as resolved.
Show resolved Hide resolved
<IncludeSymbols>true</IncludeSymbols>
96malhar marked this conversation as resolved.
Show resolved Hide resolved
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>
96malhar marked this conversation as resolved.
Show resolved Hide resolved
<IncludeSymbols>true</IncludeSymbols>
96malhar marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
10 changes: 5 additions & 5 deletions src/AWS.Messaging/AWS.Messaging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
<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>
96malhar marked this conversation as resolved.
Show resolved Hide resolved
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
96malhar marked this conversation as resolved.
Show resolved Hide resolved
</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.*" />
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
Loading