Skip to content

Commit 6b203dc

Browse files
Remove InputLoopService
1 parent 5151c34 commit 6b203dc

File tree

3 files changed

+36
-35
lines changed

3 files changed

+36
-35
lines changed

samples/aws/lambda-sqs/SQSLambda_3/RegularEndpoint/InputLoopService.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,54 @@
11
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
24
using Microsoft.Extensions.DependencyInjection;
35
using Microsoft.Extensions.Hosting;
46
using NServiceBus;
57

68
Console.Title = "RegularEndpoint";
79

810
var builder = Host.CreateApplicationBuilder(args);
9-
builder.Services.AddHostedService<InputLoopService>();
1011

1112
var endpointConfiguration = new EndpointConfiguration("RegularEndpoint");
12-
1313
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
1414
endpointConfiguration.UseTransport<SqsTransport>();
1515

16-
1716
Console.WriteLine("Press any key, the application is starting");
1817
Console.ReadKey();
1918
Console.WriteLine("Starting...");
2019

2120
builder.UseNServiceBus(endpointConfiguration);
22-
await builder.Build().RunAsync();
21+
22+
var host = builder.Build();
23+
await host.StartAsync();
24+
25+
// Get the required services
26+
var messageSession = host.Services.GetRequiredService<IMessageSession>();
27+
// Register a cancellation token to gracefully handle application shutdown
28+
var ct = host.Services.GetRequiredService<IHostApplicationLifetime>().ApplicationStopping;
29+
30+
Console.WriteLine("Press [ENTER] to send a message to the serverless endpoint queue.");
31+
Console.WriteLine("Press Ctrl+C to shut down.");
32+
33+
// Wait for user input to publish messages
34+
while (!ct.IsCancellationRequested)
35+
{
36+
if (!Console.KeyAvailable)
37+
{
38+
// If no key is pressed, wait for a short time before checking again
39+
await Task.Delay(100, CancellationToken.None);
40+
continue;
41+
}
42+
43+
var key = Console.ReadKey();
44+
Console.WriteLine();
45+
46+
if (key.Key == ConsoleKey.Enter)
47+
{
48+
await messageSession.Send("ServerlessEndpoint", new TriggerMessage());
49+
Console.WriteLine("Message sent to the serverless endpoint queue.");
50+
}
51+
}
52+
53+
// Wait for the host to stop gracefully
54+
await host.StopAsync();

samples/aws/lambda-sqs/SQSLambda_3/RegularEndpoint/ResponseMessageHandler.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
public class ResponseMessageHandler(ILogger<ResponseMessageHandler> logger) : IHandleMessages<ResponseMessage>
66
{
7-
87
public Task Handle(ResponseMessage message, IMessageHandlerContext context)
98
{
109
logger.LogInformation("Handling {MessageType} in RegularEndpoint", nameof(ResponseMessage));

0 commit comments

Comments
 (0)