Skip to content

Commit 4c71ba9

Browse files
Update to .NET 10
1 parent 6b203dc commit 4c71ba9

18 files changed

+427
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RegularEndpoint\RegularEndpoint.csproj
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29728.190
5+
MinimumVisualStudioVersion = 15.0.26730.12
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerlessEndpoint", "ServerlessEndpoint\ServerlessEndpoint.csproj", "{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RegularEndpoint", "RegularEndpoint\RegularEndpoint.csproj", "{06754C55-CA74-4F17-9472-244B8A3FEB1E}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Messages", "Messages\Messages.csproj", "{1BEFE981-8E75-4152-B6E3-8D488AE8530F}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Debug|x64 = Debug|x64
16+
Debug|x86 = Debug|x86
17+
EndGlobalSection
18+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19+
{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}.Debug|x64.ActiveCfg = Debug|Any CPU
22+
{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}.Debug|x64.Build.0 = Debug|Any CPU
23+
{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}.Debug|x86.ActiveCfg = Debug|Any CPU
24+
{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}.Debug|x86.Build.0 = Debug|Any CPU
25+
{06754C55-CA74-4F17-9472-244B8A3FEB1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{06754C55-CA74-4F17-9472-244B8A3FEB1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{06754C55-CA74-4F17-9472-244B8A3FEB1E}.Debug|x64.ActiveCfg = Debug|Any CPU
28+
{06754C55-CA74-4F17-9472-244B8A3FEB1E}.Debug|x64.Build.0 = Debug|Any CPU
29+
{06754C55-CA74-4F17-9472-244B8A3FEB1E}.Debug|x86.ActiveCfg = Debug|Any CPU
30+
{06754C55-CA74-4F17-9472-244B8A3FEB1E}.Debug|x86.Build.0 = Debug|Any CPU
31+
{1BEFE981-8E75-4152-B6E3-8D488AE8530F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32+
{1BEFE981-8E75-4152-B6E3-8D488AE8530F}.Debug|Any CPU.Build.0 = Debug|Any CPU
33+
{1BEFE981-8E75-4152-B6E3-8D488AE8530F}.Debug|x64.ActiveCfg = Debug|Any CPU
34+
{1BEFE981-8E75-4152-B6E3-8D488AE8530F}.Debug|x64.Build.0 = Debug|Any CPU
35+
{1BEFE981-8E75-4152-B6E3-8D488AE8530F}.Debug|x86.ActiveCfg = Debug|Any CPU
36+
{1BEFE981-8E75-4152-B6E3-8D488AE8530F}.Debug|x86.Build.0 = Debug|Any CPU
37+
EndGlobalSection
38+
GlobalSection(SolutionProperties) = preSolution
39+
HideSolutionNode = FALSE
40+
EndGlobalSection
41+
GlobalSection(ExtensibilityGlobals) = postSolution
42+
SolutionGuid = {6C66C18C-5075-4811-AF40-2997E8863F3B}
43+
EndGlobalSection
44+
EndGlobal
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<LangVersion>preview</LangVersion>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="NServiceBus" Version="10.0.0-alpha.1" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class ResponseMessage : IMessage
2+
{
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class TriggerMessage : IMessage
2+
{
3+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using Microsoft.Extensions.Hosting;
3+
4+
Console.Title = "RegularEndpoint";
5+
6+
var builder = Host.CreateApplicationBuilder(args);
7+
8+
var endpointConfiguration = new EndpointConfiguration("RegularEndpoint");
9+
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
10+
endpointConfiguration.UseTransport<SqsTransport>();
11+
12+
builder.UseNServiceBus(endpointConfiguration);
13+
14+
var host = builder.Build();
15+
await host.StartAsync();
16+
17+
// Get the required services
18+
var messageSession = host.Services.GetRequiredService<IMessageSession>();
19+
// Register a cancellation token to gracefully handle application shutdown
20+
var ct = host.Services.GetRequiredService<IHostApplicationLifetime>().ApplicationStopping;
21+
22+
Console.WriteLine("Press [ENTER] to send a message to the serverless endpoint queue.");
23+
Console.WriteLine("Press Ctrl+C to shut down.");
24+
25+
// Wait for user input to publish messages
26+
while (!ct.IsCancellationRequested)
27+
{
28+
if (!Console.KeyAvailable)
29+
{
30+
// If no key is pressed, wait for a short time before checking again
31+
await Task.Delay(100, CancellationToken.None);
32+
continue;
33+
}
34+
35+
var key = Console.ReadKey();
36+
Console.WriteLine();
37+
38+
if (key.Key == ConsoleKey.Enter)
39+
{
40+
await messageSession.Send("ServerlessEndpoint", new TriggerMessage());
41+
Console.WriteLine("Message sent to the serverless endpoint queue.");
42+
}
43+
}
44+
45+
// Wait for the host to stop gracefully
46+
await host.StopAsync();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<OutputType>Exe</OutputType>
6+
<LangVersion>preview</LangVersion>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\Messages\Messages.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="NServiceBus.AmazonSQS" Version="9.0.0-alpha.1" />
16+
<PackageReference Include="NServiceBus.Extensions.Hosting" Version="4.0.0-alpha.1" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Microsoft.Extensions.Logging;
2+
3+
public class ResponseMessageHandler(ILogger<ResponseMessageHandler> logger) : IHandleMessages<ResponseMessage>
4+
{
5+
public Task Handle(ResponseMessage message, IMessageHandlerContext context)
6+
{
7+
logger.LogInformation("Handling {MessageType} in RegularEndpoint", nameof(ResponseMessage));
8+
return Task.CompletedTask;
9+
}
10+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace LambdaFunctions;
2+
3+
public static class Endpoint
4+
{
5+
#region EndpointSetup
6+
public static IAwsLambdaSQSEndpoint Configuration => new AwsLambdaSQSEndpoint(context =>
7+
{
8+
var endpointConfiguration = new AwsLambdaSQSEndpointConfiguration("ServerlessEndpoint");
9+
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
10+
11+
var routing = endpointConfiguration.RoutingSettings;
12+
13+
routing.RouteToEndpoint(typeof(TriggerMessage), "ServerlessEndpoint");
14+
routing.RouteToEndpoint(typeof(ResponseMessage), "RegularEndpoint");
15+
16+
return endpointConfiguration;
17+
});
18+
#endregion
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Amazon.Lambda.Annotations;
2+
using Amazon.Lambda.Annotations.APIGateway;
3+
using Amazon.Lambda.Core;
4+
5+
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
6+
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
7+
8+
namespace LambdaFunctions
9+
{
10+
public class HttpLambda
11+
{
12+
#region HttpFunctionHandler
13+
[LambdaFunction(Policies = "AWSLambda_FullAccess, AmazonSQSFullAccess")]
14+
[HttpApi(LambdaHttpMethod.Get, "/")]
15+
public async Task<string> HttpGetHandler(ILambdaContext context)
16+
{
17+
await serverlessEndpoint.Send(new TriggerMessage(), context);
18+
return $"{nameof(TriggerMessage)} sent.";
19+
}
20+
21+
#endregion
22+
23+
static readonly IAwsLambdaSQSEndpoint serverlessEndpoint = Endpoint.Configuration;
24+
}
25+
}

0 commit comments

Comments
 (0)