1
1
using System ;
2
+ using Microsoft . Extensions . Hosting ;
2
3
using Endpoint ;
4
+ using Microsoft . Extensions . DependencyInjection ;
3
5
using NServiceBus ;
4
6
5
- var endpointConfiguration = new EndpointConfiguration ( Console . Title = "TracingEndpoint" ) ;
7
+ Console . Title = "TracingEndpoint" ;
6
8
7
- endpointConfiguration . UseSerialization < SystemJsonSerializer > ( ) ;
8
- endpointConfiguration . UseTransport < LearningTransport > ( ) ;
9
+ var host = Host . CreateDefaultBuilder ( args )
10
+ . UseConsoleLifetime ( )
11
+ . UseNServiceBus ( _ =>
12
+ {
13
+ var endpointConfiguration = new EndpointConfiguration ( "TracingEndpoint" ) ;
14
+
15
+ endpointConfiguration . UseSerialization < SystemJsonSerializer > ( ) ;
16
+ endpointConfiguration . UseTransport < LearningTransport > ( ) ;
17
+
18
+ NewRelicMetrics . Setup ( endpointConfiguration ) ;
19
+
20
+ return endpointConfiguration ;
21
+ } )
22
+ . Build ( ) ;
9
23
10
- NewRelicMetrics . Setup ( endpointConfiguration ) ;
24
+ await host . StartAsync ( ) ;
11
25
12
- var endpointInstance = await NServiceBus . Endpoint . Start ( endpointConfiguration ) ;
26
+ var endpointInstance = host . Services . GetRequiredService < IMessageSession > ( ) ;
13
27
14
28
#region newrelic-load-simulator
15
29
22
36
{
23
37
Console . WriteLine ( "Endpoint started." ) ;
24
38
Console . WriteLine ( "Press [ENTER] to send additional messages." ) ;
25
- Console . WriteLine ( "Press [ESC ] to quit." ) ;
39
+ Console . WriteLine ( "Press [Q ] to quit." ) ;
26
40
27
41
while ( true )
28
42
{
29
43
switch ( Console . ReadKey ( true ) . Key )
30
44
{
31
- case ConsoleKey . Escape :
45
+ case ConsoleKey . Q :
32
46
return ;
33
47
case ConsoleKey . Enter :
34
48
await endpointInstance . SendLocal ( new SomeCommand ( ) ) ;
39
53
finally
40
54
{
41
55
await simulator . Stop ( ) ;
42
- await endpointInstance . Stop ( ) ;
56
+ await host . StopAsync ( ) ;
43
57
}
0 commit comments