Skip to content

Commit d57c4e8

Browse files
authored
Fix incorrect use of InputLoopService in simple ASQ transport sample (#7441)
* Fix incorrect use of InputLoopService in simple ASQ transport sample * Use correct Shared namespace for messages
1 parent b325411 commit d57c4e8

File tree

6 files changed

+34
-43
lines changed

6 files changed

+34
-43
lines changed

samples/azure/storage-queues/ASQN_13/Endpoint1/Endpoint2ResponseHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using System.Threading.Tasks;
22
using NServiceBus;
33
using Microsoft.Extensions.Logging;
4+
using Shared;
45

56
public sealed class Endpoint2ResponseHandler(ILogger<Endpoint2ResponseHandler> logger)
6-
: IHandleMessages<Endpoint2.MyResponse>
7+
: IHandleMessages<MyResponse>
78
{
8-
public Task Handle(Endpoint2.MyResponse message, IMessageHandlerContext context)
9+
public Task Handle(MyResponse message, IMessageHandlerContext context)
910
{
1011
logger.LogInformation("Received MyResponse: {Property}", message.Property);
1112
return Task.CompletedTask;

samples/azure/storage-queues/ASQN_13/Endpoint1/InputLoopService.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

samples/azure/storage-queues/ASQN_13/Endpoint1/Program.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System;
2-
using Endpoint1;
32
using Microsoft.Extensions.DependencyInjection;
43
using Microsoft.Extensions.Hosting;
54
using NServiceBus;
5+
using Shared;
66

77
var host = Host.CreateDefaultBuilder(args)
8-
.ConfigureServices((hostContext, services) => { services.AddHostedService<InputLoopService>(); })
98
.UseNServiceBus(x =>
109
{
1110
#region endpointName
@@ -21,7 +20,7 @@
2120

2221
var transport = new AzureStorageQueueTransport("UseDevelopmentStorage=true");
2322
var routingSettings = endpointConfiguration.UseTransport(transport);
24-
routingSettings.RouteToEndpoint(typeof(Endpoint2.MyRequest), "Samples-Azure-StorageQueues-Endpoint2");
23+
routingSettings.RouteToEndpoint(typeof(MyRequest), "Samples-Azure-StorageQueues-Endpoint2");
2524

2625
#endregion
2726

@@ -39,4 +38,26 @@
3938
return endpointConfiguration;
4039
}).Build();
4140

42-
await host.RunAsync();
41+
await host.StartAsync();
42+
43+
var messageSession = host.Services.GetRequiredService<IMessageSession>();
44+
45+
Console.WriteLine("Press 'enter' to send a message");
46+
while (true)
47+
{
48+
var key = Console.ReadKey();
49+
Console.WriteLine();
50+
51+
if (key.Key != ConsoleKey.Enter)
52+
{
53+
break;
54+
}
55+
56+
var message = new MyRequest("Hello from Endpoint1");
57+
58+
await messageSession.Send(message);
59+
60+
Console.WriteLine("MyRequest sent");
61+
}
62+
63+
await host.StopAsync();
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using System.Threading.Tasks;
22
using NServiceBus;
33
using Microsoft.Extensions.Logging;
4+
using Shared;
45

56
public sealed class MyRequestResponseHandler(ILogger<MyRequestResponseHandler> logger)
6-
: IHandleMessages<Endpoint2.MyRequest>
7+
: IHandleMessages<MyRequest>
78
{
8-
public Task Handle(Endpoint2.MyRequest message, IMessageHandlerContext context)
9+
public Task Handle(MyRequest message, IMessageHandlerContext context)
910
{
1011
logger.LogInformation("Received MyRequest: {Property}", message.Property);
11-
var myResponse = new Endpoint2.MyResponse("Hello from Endpoint2");
12+
var myResponse = new MyResponse("Hello from Endpoint2");
1213
return context.Reply(myResponse);
1314
}
1415
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using NServiceBus;
22

3-
namespace Endpoint2;
3+
namespace Shared;
44

55
public record MyRequest(string Property) : IMessage;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using NServiceBus;
22

3-
namespace Endpoint2;
3+
namespace Shared;
44

55
public record MyResponse(string Property) : IMessage;

0 commit comments

Comments
 (0)