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

Add support for Native AOT (Retarget library to .NET 8) #184

Open
wants to merge 4 commits into
base: v4sdk-development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .autover/changes/d2fd7dc5-4c90-4697-8dbe-297f6e15cf88.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"Projects": [
{
"Name": "AWS.Messaging",
"Type": "Minor",
"ChangelogMessages": [
"Update .NET target to .NET 8",
"Add trimming support for Native AOT compatiblity"
]
},
{
"Name": "AWS.Messaging.Lambda",
"Type": "Minor",
"ChangelogMessages": [
"Update .NET target to .NET 8",
"Add trimming support for Native AOT compatiblity"
]
},
{
"Name": "AWS.Messaging.Telemetry.OpenTelemetry",
"Type": "Minor",
"ChangelogMessages": [
"Update .NET target to .NET 8",
"Add trimming support for Native AOT compatiblity"
]
}

]
}
2 changes: 1 addition & 1 deletion sampleapps/LambdaMessaging/LambdaMessaging.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand Down
4 changes: 2 additions & 2 deletions sampleapps/LambdaMessaging/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"Mock Lambda Test Tool": {
"commandName": "Executable",
"commandLineArgs": "--port 5050",
"workingDirectory": ".\\bin\\$(Configuration)\\net6.0",
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-6.0.exe"
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0",
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-8.0.exe"
}
}
}
2 changes: 1 addition & 1 deletion sampleapps/PollyIntegration/PollyIntegration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion sampleapps/PublisherAPI/PublisherAPI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion sampleapps/SubscriberService/SubscriberService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/AWS.Messaging.Lambda/AWS.Messaging.Lambda.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>true</IsPackable>
<Authors>Amazon Web Services</Authors>
<Company>Amazon Web Services</Company>
Expand All @@ -21,6 +21,7 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

<ItemGroup>
Expand Down
19 changes: 11 additions & 8 deletions src/AWS.Messaging.Lambda/Services/DefaultLambdaMessageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,21 @@ public async Task DeleteMessagesAsync(IEnumerable<MessageEnvelope> messages, Can

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

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

foreach (var successMessage in successFulResponse)
if (response.Successful != null)
{
_logger.LogTrace("Deleted message {MessageId} from queue {SubscriberEndpoint} successfully", successMessage.Id, _configuration.SubscriberEndpoint);
foreach (var successMessage in response.Successful)
{
_logger.LogTrace("Deleted message {MessageId} from queue {SubscriberEndpoint} successfully", successMessage.Id, _configuration.SubscriberEndpoint);
}
}

foreach (var failedMessage in failedResponse)
if (response.Failed != null)
{
_logger.LogError("Failed to delete message {FailedMessageId} from queue {SubscriberEndpoint}: {FailedMessage}",
failedMessage.Id, _configuration.SubscriberEndpoint, failedMessage.Message);
foreach (var failedMessage in response.Failed)
{
_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
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
Expand All @@ -23,6 +23,7 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics;
using System.Text.Json;
using AWS.Messaging.Internal;
using OpenTelemetry;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Trace;
Expand Down Expand Up @@ -74,7 +75,7 @@ public void RecordTelemetryContext(MessageEnvelope envelope)
/// <param name="value">Context value</param>
private void InjectTraceContextIntoEnvelope(MessageEnvelope envelope, string key, string value)
{
envelope.Metadata[key] = JsonSerializer.SerializeToElement(value);
envelope.Metadata[key] = JsonSerializer.SerializeToElement(value, typeof(string), MessagingJsonSerializerContext.Default);
}

private bool _disposed;
Expand Down
12 changes: 7 additions & 5 deletions src/AWS.Messaging/AWS.Messaging.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>true</IsPackable>
<Product>AWS Message Processing Framework</Product>
<Authors>Amazon Web Services</Authors>
Expand All @@ -15,20 +15,22 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<WarningsAsErrors>CA1727</WarningsAsErrors>
<NoWarn>CS1591</NoWarn>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CS1591 is the code for no docs on public API surface. I had to add this because the code generated via the JSON serializer for the internal MessageJsonSerializerContext doesn't have any docs. I tried a variety of ways to get the warning to ignore that generated code but nothing stuck.

<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\public.snk</AssemblyOriginatorKeyFile>
<Version>2.0.0-preview.1</Version>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

<ItemGroup>
<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="AWSSDK.EventBridge" Version="4.0.0-preview.10" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="4.0.0-preview.10" />
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="4.0.0-preview.10" />
<PackageReference Include="AWSSDK.SQS" Version="4.0.0-preview.10" />
<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
11 changes: 7 additions & 4 deletions src/AWS.Messaging/Configuration/IMessageBusBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics.CodeAnalysis;
using AWS.Messaging.Publishers.EventBridge;
using AWS.Messaging.Publishers.SNS;
using AWS.Messaging.Publishers.SQS;
Expand All @@ -23,7 +24,7 @@ public interface IMessageBusBuilder
/// <param name="queueUrl">The SQS queue URL to publish the message to. If the queue URL is null, a message-specific queue
/// URL must be specified on the <see cref="SQSOptions"/> when sending a message.</param>
/// <param name="messageTypeIdentifier">The language-agnostic message type identifier. If not specified, the .NET type will be used.</param>
IMessageBusBuilder AddSQSPublisher<TMessage>(string? queueUrl, string? messageTypeIdentifier = null);
IMessageBusBuilder AddSQSPublisher<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TMessage>(string? queueUrl, string? messageTypeIdentifier = null);

/// <summary>
/// Adds an SNS Publisher to the framework which will handle publishing
Expand All @@ -32,7 +33,7 @@ public interface IMessageBusBuilder
/// <param name="topicUrl">The SNS topic URL to publish the message to. If the topic URL is null, a message-specific
/// topic URL must be set on the <see cref="SNSOptions"/> when publishing a message.</param>
/// <param name="messageTypeIdentifier">The language-agnostic message type identifier. If not specified, the .NET type will be used.</param>
IMessageBusBuilder AddSNSPublisher<TMessage>(string? topicUrl, string? messageTypeIdentifier = null);
IMessageBusBuilder AddSNSPublisher<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TMessage>(string? topicUrl, string? messageTypeIdentifier = null);

/// <summary>
/// Adds an EventBridge Publisher to the framework which will handle publishing the defined message type to the specified EventBridge event bus name.
Expand All @@ -42,14 +43,14 @@ public interface IMessageBusBuilder
/// a message-specific event bus must be set on the <see cref="EventBridgeOptions"/> when sending an event.</param>
/// <param name="messageTypeIdentifier">The language-agnostic message type identifier. If not specified, the .NET type will be used.</param>
/// <param name="options">Contains additional properties that can be set while configuring an EventBridge publisher</param>
IMessageBusBuilder AddEventBridgePublisher<TMessage>(string? eventBusName, string? messageTypeIdentifier = null, EventBridgePublishOptions? options = null);
IMessageBusBuilder AddEventBridgePublisher<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TMessage>(string? eventBusName, string? messageTypeIdentifier = null, EventBridgePublishOptions? options = null);

/// <summary>
/// Add a message handler for a given message type.
/// The message handler contains the business logic of how to process a given message type.
/// </summary>
/// <param name="messageTypeIdentifier">The language-agnostic message type identifier. If not specified, the .NET type will be used.</param>
IMessageBusBuilder AddMessageHandler<THandler, TMessage>(string? messageTypeIdentifier = null)
IMessageBusBuilder AddMessageHandler<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] THandler, TMessage>(string? messageTypeIdentifier = null)
where THandler : IMessageHandler<TMessage>;

/// <summary>
Expand Down Expand Up @@ -89,6 +90,8 @@ IMessageBusBuilder AddMessageHandler<THandler, TMessage>(string? messageTypeIden
/// and apply the Message bus configuration based on that section.
/// </summary>
/// <param name="configuration"><see cref="IConfiguration"/></param>
[RequiresDynamicCode("This method requires loading types dynamically as defined in the configuration system.")]
[RequiresUnreferencedCode("This method requires loading types dynamically as defined in the configuration system.")]
IMessageBusBuilder LoadConfigurationFromSettings(IConfiguration configuration);

/// <summary>
Expand Down
Loading
Loading