Skip to content

Commit cdbcf6e

Browse files
authored
Fixed missing route for Message1/MyRequest in Azure Storage Queue Sample (#7125)
* Fixed missing route for Message1/MyRequest, and made more modern * Update message name * Bumped `reviewed` * Update samples/azure/storage-queues/sample.md * Use log templates * Revert log template o nold versions as that is still NSB logger abstraction
1 parent a55e235 commit cdbcf6e

30 files changed

+144
-166
lines changed

samples/azure/storage-queues/ASQN_10/Endpoint1/Message2Handler.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
using NServiceBus;
33
using NServiceBus.Logging;
44

5-
public class Message2Handler :
6-
IHandleMessages<Message2>
5+
public class MyResponseHandler :
6+
IHandleMessages<MyResponse>
77
{
8-
static ILog log = LogManager.GetLogger<Message2Handler>();
8+
static ILog log = LogManager.GetLogger<MyResponseHandler>();
99

10-
public Task Handle(Message2 message, IMessageHandlerContext context)
10+
public Task Handle(MyResponse message, IMessageHandlerContext context)
1111
{
1212
log.Info($"Received Message2: {message.Property}");
1313
return Task.CompletedTask;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ static async Task Main()
5050
break;
5151
}
5252

53-
var message = new Message1
53+
var message = new MyRequest
5454
{
5555
Property = "Hello from Endpoint1"
5656
};
5757
await endpointInstance.Send("Samples-Azure-StorageQueues-Endpoint2", message);
58-
Console.WriteLine("Message1 sent");
58+
Console.WriteLine("MyRequest sent");
5959
}
6060
await endpointInstance.Stop();
6161
}

samples/azure/storage-queues/ASQN_10/Endpoint2/Message1Handler.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
using NServiceBus;
33
using NServiceBus.Logging;
44

5-
public class Message1Handler :
6-
IHandleMessages<Message1>
5+
public class MyRequestHandler :
6+
IHandleMessages<MyRequest>
77
{
8-
static ILog log = LogManager.GetLogger<Message1Handler>();
8+
static ILog log = LogManager.GetLogger<MyRequestHandler>();
99

10-
public Task Handle(Message1 message, IMessageHandlerContext context)
10+
public Task Handle(MyRequest message, IMessageHandlerContext context)
1111
{
1212
log.Info($"Received Message1: {message.Property}");
13-
var message2 = new Message2
13+
var MyResponse = new MyResponse
1414
{
1515
Property = "Hello from Endpoint2"
1616
};
17-
return context.Reply(message2);
17+
return context.Reply(MyResponse);
1818
}
1919
}

samples/azure/storage-queues/ASQN_10/Shared/Message1.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using NServiceBus;
22

3-
public class Message1 :
3+
public class MyRequest :
44
IMessage
55
{
66
public string Property { get; set; }

samples/azure/storage-queues/ASQN_10/Shared/Message2.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using NServiceBus;
22

3-
public class Message2 :
3+
public class MyResponse :
44
IMessage
55
{
66
public string Property { get; set; }

samples/azure/storage-queues/ASQN_11/Endpoint1/Message2Handler.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
using NServiceBus;
33
using NServiceBus.Logging;
44

5-
public class Message2Handler :
6-
IHandleMessages<Message2>
5+
public class MyResponseHandler :
6+
IHandleMessages<MyResponse>
77
{
8-
static ILog log = LogManager.GetLogger<Message2Handler>();
8+
static ILog log = LogManager.GetLogger<MyResponseHandler>();
99

10-
public Task Handle(Message2 message, IMessageHandlerContext context)
10+
public Task Handle(MyResponse message, IMessageHandlerContext context)
1111
{
1212
log.Info($"Received Message2: {message.Property}");
1313
return Task.CompletedTask;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ static async Task Main()
4747
break;
4848
}
4949

50-
var message = new Message1
50+
var message = new MyRequest
5151
{
5252
Property = "Hello from Endpoint1"
5353
};
5454
await endpointInstance.Send("Samples-Azure-StorageQueues-Endpoint2", message);
55-
Console.WriteLine("Message1 sent");
55+
Console.WriteLine("MyRequest sent");
5656
}
5757
await endpointInstance.Stop();
5858
}

samples/azure/storage-queues/ASQN_11/Endpoint2/Message1Handler.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
using NServiceBus;
33
using NServiceBus.Logging;
44

5-
public class Message1Handler :
6-
IHandleMessages<Message1>
5+
public class MyRequestHandler :
6+
IHandleMessages<MyRequest>
77
{
8-
static ILog log = LogManager.GetLogger<Message1Handler>();
8+
static ILog log = LogManager.GetLogger<MyRequestHandler>();
99

10-
public Task Handle(Message1 message, IMessageHandlerContext context)
10+
public Task Handle(MyRequest message, IMessageHandlerContext context)
1111
{
1212
log.Info($"Received Message1: {message.Property}");
13-
var message2 = new Message2
13+
var MyResponse = new MyResponse
1414
{
1515
Property = "Hello from Endpoint2"
1616
};
17-
return context.Reply(message2);
17+
return context.Reply(MyResponse);
1818
}
1919
}

samples/azure/storage-queues/ASQN_11/Shared/Message1.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using NServiceBus;
22

3-
public class Message1 :
3+
public class MyRequest :
44
IMessage
55
{
66
public string Property { get; set; }

samples/azure/storage-queues/ASQN_11/Shared/Message2.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using NServiceBus;
22

3-
public class Message2 :
3+
public class MyResponse :
44
IMessage
55
{
66
public string Property { get; set; }

samples/azure/storage-queues/ASQN_12/Endpoint1/Message2Handler.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
using NServiceBus;
33
using NServiceBus.Logging;
44

5-
public class Message2Handler :
6-
IHandleMessages<Message2>
5+
public class MyResponseHandler :
6+
IHandleMessages<MyResponse>
77
{
8-
static ILog log = LogManager.GetLogger<Message2Handler>();
8+
static ILog log = LogManager.GetLogger<MyResponseHandler>();
99

10-
public Task Handle(Message2 message, IMessageHandlerContext context)
10+
public Task Handle(MyResponse message, IMessageHandlerContext context)
1111
{
1212
log.Info($"Received Message2: {message.Property}");
1313
return Task.CompletedTask;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ static async Task Main()
4747
break;
4848
}
4949

50-
var message = new Message1
50+
var message = new MyRequest
5151
{
5252
Property = "Hello from Endpoint1"
5353
};
5454
await endpointInstance.Send("Samples-Azure-StorageQueues-Endpoint2", message);
55-
Console.WriteLine("Message1 sent");
55+
Console.WriteLine("MyRequest sent");
5656
}
5757
await endpointInstance.Stop();
5858
}

samples/azure/storage-queues/ASQN_12/Endpoint2/Message1Handler.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
using NServiceBus;
33
using NServiceBus.Logging;
44

5-
public class Message1Handler :
6-
IHandleMessages<Message1>
5+
public class MyRequestHandler :
6+
IHandleMessages<MyRequest>
77
{
8-
static ILog log = LogManager.GetLogger<Message1Handler>();
8+
static ILog log = LogManager.GetLogger<MyRequestHandler>();
99

10-
public Task Handle(Message1 message, IMessageHandlerContext context)
10+
public Task Handle(MyRequest message, IMessageHandlerContext context)
1111
{
1212
log.Info($"Received Message1: {message.Property}");
13-
var message2 = new Message2
13+
var MyResponse = new MyResponse
1414
{
1515
Property = "Hello from Endpoint2"
1616
};
17-
return context.Reply(message2);
17+
return context.Reply(MyResponse);
1818
}
1919
}

samples/azure/storage-queues/ASQN_12/Shared/Message1.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using NServiceBus;
22

3-
public class Message1 :
3+
public class MyRequest :
44
IMessage
55
{
66
public string Property { get; set; }

samples/azure/storage-queues/ASQN_12/Shared/Message2.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using NServiceBus;
22

3-
public class Message2 :
3+
public class MyResponse :
44
IMessage
55
{
66
public string Property { get; set; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Threading.Tasks;
2+
using NServiceBus;
3+
using Microsoft.Extensions.Logging;
4+
5+
public sealed class Endpoint2ResponseHandler(ILogger<Endpoint2ResponseHandler> logger)
6+
: IHandleMessages<Endpoint2.MyResponse>
7+
{
8+
public Task Handle(Endpoint2.MyResponse message, IMessageHandlerContext context)
9+
{
10+
logger.LogInformation("Received MyResponse: {Property}", message.Property);
11+
return Task.CompletedTask;
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
11
using System;
22
using System.Threading;
33
using System.Threading.Tasks;
4+
using Endpoint2;
45
using Microsoft.Extensions.Hosting;
56
using NServiceBus;
67

7-
namespace Endpoint1
8+
namespace Endpoint1;
9+
10+
public sealed class InputLoopService(IMessageSession messageSession) : BackgroundService
811
{
9-
public class InputLoopService(IMessageSession messageSession) : BackgroundService
12+
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
1013
{
11-
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
14+
Console.WriteLine("Press 'enter' to send a message");
15+
while (true)
1216
{
13-
Console.WriteLine("Press 'enter' to send a message");
14-
while (true)
15-
{
16-
var key = Console.ReadKey();
17-
Console.WriteLine();
17+
var key = Console.ReadKey();
18+
Console.WriteLine();
1819

19-
if (key.Key != ConsoleKey.Enter)
20-
{
21-
break;
22-
}
20+
if (key.Key != ConsoleKey.Enter)
21+
{
22+
break;
23+
}
2324

24-
var message = new Message1
25-
{
26-
Property = "Hello from Endpoint1"
27-
};
25+
var message = new MyRequest("Hello from Endpoint1");
2826

29-
await messageSession.Send(message, stoppingToken);
27+
await messageSession.Send(message, stoppingToken);
3028

31-
Console.WriteLine("Message1 sent");
32-
}
29+
Console.WriteLine("MyRequest sent");
3330
}
3431
}
35-
}
36-
32+
}

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

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,42 @@
11
using System;
2-
using System.Threading.Tasks;
32
using Endpoint1;
43
using Microsoft.Extensions.DependencyInjection;
54
using Microsoft.Extensions.Hosting;
65
using NServiceBus;
76

8-
class Program
9-
{
10-
public static async Task Main(string[] args)
7+
var host = Host.CreateDefaultBuilder(args)
8+
.ConfigureServices((hostContext, services) => { services.AddHostedService<InputLoopService>(); })
9+
.UseNServiceBus(x =>
1110
{
12-
await CreateHostBuilder(args).Build().RunAsync();
13-
}
11+
#region endpointName
1412

15-
public static IHostBuilder CreateHostBuilder(string[] args) =>
16-
Host.CreateDefaultBuilder(args)
17-
.ConfigureServices((hostContext, services) =>
18-
{
19-
services.AddHostedService<InputLoopService>();
13+
var endpointName = "Samples.Azure.StorageQueues.Endpoint1.With.A.Very.Long.Name.And.Invalid.Characters";
14+
var endpointConfiguration = new EndpointConfiguration(endpointName);
2015

21-
}).UseNServiceBus(x =>
22-
{
23-
#region endpointName
16+
#endregion
2417

25-
var endpointName = "Samples.Azure.StorageQueues.Endpoint1.With.A.Very.Long.Name.And.Invalid.Characters";
26-
var endpointConfiguration = new EndpointConfiguration(endpointName);
18+
Console.Title = endpointName;
2719

28-
#endregion
20+
#region config
2921

30-
Console.Title = endpointName;
22+
var transport = new AzureStorageQueueTransport("UseDevelopmentStorage=true");
23+
var routingSettings = endpointConfiguration.UseTransport(transport);
24+
routingSettings.RouteToEndpoint(typeof(Endpoint2.MyRequest), "Samples-Azure-StorageQueues-Endpoint2");
3125

32-
#region config
26+
#endregion
3327

34-
var transport = new AzureStorageQueueTransport("UseDevelopmentStorage=true");
35-
var routingSettings = endpointConfiguration.UseTransport(transport);
28+
#region sanitization
3629

37-
#endregion
30+
transport.QueueNameSanitizer = BackwardsCompatibleQueueNameSanitizer.WithMd5Shortener;
3831

39-
#region sanitization
32+
#endregion
4033

41-
transport.QueueNameSanitizer = BackwardsCompatibleQueueNameSanitizer.WithMd5Shortener;
34+
routingSettings.DisablePublishing();
35+
endpointConfiguration.UsePersistence<LearningPersistence>();
36+
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
37+
endpointConfiguration.EnableInstallers();
4238

43-
#endregion
39+
return endpointConfiguration;
40+
}).Build();
4441

45-
routingSettings.DisablePublishing();
46-
endpointConfiguration.UsePersistence<LearningPersistence>();
47-
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
48-
endpointConfiguration.EnableInstallers();
49-
50-
51-
return endpointConfiguration;
52-
});
53-
54-
}
42+
await host.RunAsync();

0 commit comments

Comments
 (0)