Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
Console.WriteLine("Message sent to the serverless endpoint queue.");
}

await host.StopAsync();
await host.StopAsync();
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

public class ResponseMessageHandler(ILogger<ResponseMessageHandler> logger) : IHandleMessages<ResponseMessage>
{

public Task Handle(ResponseMessage message, IMessageHandlerContext context)
{
logger.LogInformation("Handling {MessageType} in RegularEndpoint", nameof(ResponseMessage));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using NServiceBus;
using NServiceBus.Logging;

#region TriggerMessageHandler
public class TriggerMessageHandler(ILogger<TriggerMessageHandler> logger) : IHandleMessages<TriggerMessage>
public class TriggerMessageHandler : IHandleMessages<TriggerMessage>
{
static readonly ILog Log = LogManager.GetLogger<TriggerMessageHandler>();

public async Task Handle(TriggerMessage message, IMessageHandlerContext context)
{
logger.LogInformation("Handling {MessageType} in ServerlessEndpoint.", nameof(TriggerMessage));
Log.Info($"Handling {nameof(TriggerMessage)} in ServerlessEndpoint.");
await context.Send(new ResponseMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "Template that creates an SQS queue and a function that is invoked when a new message arrives. This template is partially managed by Amazon.Lambda.Annotations (v1.7.0.0).",
"Description": "Template that creates an SQS queue and a function that is invoked when a new message arrives. This template is partially managed by Amazon.Lambda.Annotations (v1.8.0.0).",
"Resources": {
"ErrorQueue": {
"Properties": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RegularEndpoint\RegularEndpoint.csproj
44 changes: 44 additions & 0 deletions samples/aws/lambda-sqs/SQSLambda_4/AWSLambda-SQS.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29728.190
MinimumVisualStudioVersion = 15.0.26730.12
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerlessEndpoint", "ServerlessEndpoint\ServerlessEndpoint.csproj", "{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RegularEndpoint", "RegularEndpoint\RegularEndpoint.csproj", "{06754C55-CA74-4F17-9472-244B8A3FEB1E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Messages", "Messages\Messages.csproj", "{1BEFE981-8E75-4152-B6E3-8D488AE8530F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}.Debug|x64.ActiveCfg = Debug|Any CPU
{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}.Debug|x64.Build.0 = Debug|Any CPU
{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}.Debug|x86.ActiveCfg = Debug|Any CPU
{D9FB3A23-D74F-4754-9A22-ACF829EEEB70}.Debug|x86.Build.0 = Debug|Any CPU
{06754C55-CA74-4F17-9472-244B8A3FEB1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06754C55-CA74-4F17-9472-244B8A3FEB1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06754C55-CA74-4F17-9472-244B8A3FEB1E}.Debug|x64.ActiveCfg = Debug|Any CPU
{06754C55-CA74-4F17-9472-244B8A3FEB1E}.Debug|x64.Build.0 = Debug|Any CPU
{06754C55-CA74-4F17-9472-244B8A3FEB1E}.Debug|x86.ActiveCfg = Debug|Any CPU
{06754C55-CA74-4F17-9472-244B8A3FEB1E}.Debug|x86.Build.0 = Debug|Any CPU
{1BEFE981-8E75-4152-B6E3-8D488AE8530F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BEFE981-8E75-4152-B6E3-8D488AE8530F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BEFE981-8E75-4152-B6E3-8D488AE8530F}.Debug|x64.ActiveCfg = Debug|Any CPU
{1BEFE981-8E75-4152-B6E3-8D488AE8530F}.Debug|x64.Build.0 = Debug|Any CPU
{1BEFE981-8E75-4152-B6E3-8D488AE8530F}.Debug|x86.ActiveCfg = Debug|Any CPU
{1BEFE981-8E75-4152-B6E3-8D488AE8530F}.Debug|x86.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6C66C18C-5075-4811-AF40-2997E8863F3B}
EndGlobalSection
EndGlobal
13 changes: 13 additions & 0 deletions samples/aws/lambda-sqs/SQSLambda_4/Messages/Messages.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>14.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NServiceBus" Version="10.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class ResponseMessage : IMessage
{
}
3 changes: 3 additions & 0 deletions samples/aws/lambda-sqs/SQSLambda_4/Messages/TriggerMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class TriggerMessage : IMessage
{
}
40 changes: 40 additions & 0 deletions samples/aws/lambda-sqs/SQSLambda_4/RegularEndpoint/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

Console.Title = "RegularEndpoint";

var endpointConfiguration = new EndpointConfiguration("RegularEndpoint");

endpointConfiguration.UseSerialization<SystemJsonSerializer>();
endpointConfiguration.UseTransport<SqsTransport>();

Console.WriteLine("Starting...");

var builder = Host.CreateApplicationBuilder(args);

builder.UseNServiceBus(endpointConfiguration);

var host = builder.Build();

await host.StartAsync();

var messageSession = host.Services.GetRequiredService<IMessageSession>();

Console.WriteLine("Press [ENTER] to send a message to the serverless endpoint queue.");
Console.WriteLine("Press any other key to exit.");

while (true)
{
var key = Console.ReadKey();
Console.WriteLine();

if (key.Key != ConsoleKey.Enter)
{
break;
}

await messageSession.Send("ServerlessEndpoint", new TriggerMessage());
Console.WriteLine("Message sent to the serverless endpoint queue.");
}

await host.StopAsync();
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>14.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Messages\Messages.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="NServiceBus.AmazonSQS" Version="9.*" />
<PackageReference Include="NServiceBus.Extensions.Hosting" Version="4.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.Extensions.Logging;

public class ResponseMessageHandler(ILogger<ResponseMessageHandler> logger) : IHandleMessages<ResponseMessage>
{
public Task Handle(ResponseMessage message, IMessageHandlerContext context)
{
logger.LogInformation("Handling {MessageType} in RegularEndpoint", nameof(ResponseMessage));
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace LambdaFunctions;

public static class Endpoint
{
#region EndpointSetup
public static IAwsLambdaSQSEndpoint Configuration => new AwsLambdaSQSEndpoint(context =>
{
var endpointConfiguration = new AwsLambdaSQSEndpointConfiguration("ServerlessEndpoint");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

var routing = endpointConfiguration.RoutingSettings;

routing.RouteToEndpoint(typeof(TriggerMessage), "ServerlessEndpoint");
routing.RouteToEndpoint(typeof(ResponseMessage), "RegularEndpoint");

return endpointConfiguration;
});
#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Amazon.Lambda.Annotations;
using Amazon.Lambda.Annotations.APIGateway;
using Amazon.Lambda.Core;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace LambdaFunctions
{
public class HttpLambda
{
#region HttpFunctionHandler
[LambdaFunction(Policies = "AWSLambda_FullAccess, AmazonSQSFullAccess")]
[HttpApi(LambdaHttpMethod.Get, "/")]
public async Task<string> HttpGetHandler(ILambdaContext context)
{
await serverlessEndpoint.Send(new TriggerMessage(), context);
return $"{nameof(TriggerMessage)} sent.";
}

#endregion

static readonly IAwsLambdaSQSEndpoint serverlessEndpoint = Endpoint.Configuration;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"Mock Lambda Test Tool": {
"commandName": "Executable",
"commandLineArgs": "--port 5050",
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0",
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-8.0.exe"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>14.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Messages\Messages.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Amazon.Lambda.Annotations" Version="1.*" />
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.*" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.*" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.*" />
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.*" />
<PackageReference Include="NServiceBus.AmazonSQS" Version="9.*" />
<PackageReference Include="NServiceBus.AwsLambda.SQS" Version="4.*" />
<PackageReference Include="NServiceBus.Extensions.Hosting" Version="4.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerlessEndpoint", "ServerlessEndpoint.csproj", "{5203F0FC-9459-4724-C2D4-BA60791FED68}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5203F0FC-9459-4724-C2D4-BA60791FED68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5203F0FC-9459-4724-C2D4-BA60791FED68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5203F0FC-9459-4724-C2D4-BA60791FED68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5203F0FC-9459-4724-C2D4-BA60791FED68}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6FBD541B-2DD7-43F4-9807-269CEA802E90}
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions samples/aws/lambda-sqs/SQSLambda_4/ServerlessEndpoint/SqsLambda.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Amazon.Lambda.Core;
using Amazon.Lambda.SQSEvents;

namespace LambdaFunctions
{
public class SqsLambda
{
#region SqsFunctionHandler
public async Task FunctionHandler(SQSEvent evnt, ILambdaContext context)
{
using var cancellationTokenSource =
new CancellationTokenSource(context.RemainingTime.Subtract(DefaultRemainingTimeGracePeriod));

await serverlessEndpoint.Process(evnt, context, cancellationTokenSource.Token);
}
#endregion

static readonly TimeSpan DefaultRemainingTimeGracePeriod = TimeSpan.FromSeconds(10);
static readonly IAwsLambdaSQSEndpoint serverlessEndpoint = Endpoint.Configuration;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using NServiceBus.Logging;

#region TriggerMessageHandler
public class TriggerMessageHandler : IHandleMessages<TriggerMessage>
{
static readonly ILog Log = LogManager.GetLogger<TriggerMessageHandler>();

public async Task Handle(TriggerMessage message, IMessageHandlerContext context)
{
Log.Info($"Handling {nameof(TriggerMessage)} in ServerlessEndpoint.");
await context.Send(new ResponseMessage());
}
}
#endregion
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Information": [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
"dotnet lambda help",
"All the command line options for the Lambda command can be specified in this file."
],
"profile": "default",
"region": "ap-southeast-2",
"configuration": "Debug",
"framework": "net8.0",
"template": "serverless.template",
"template-parameters": "",
"stack-name": "nservicebus-aws-lambda-sample-jtd",
"s3-bucket": "nservicebus-aws-lambda-sample-jtd"
}
Loading