1
1
using System ;
2
+ using Microsoft . Extensions . DependencyInjection ;
2
3
using NServiceBus ;
4
+ using Microsoft . Extensions . Hosting ;
3
5
4
6
const string EndpointName = "Samples.Metrics.Tracing.Endpoint" ;
5
7
6
8
Console . Title = EndpointName ;
7
- var endpointConfiguration = new EndpointConfiguration ( EndpointName ) ;
8
9
9
- endpointConfiguration . UseSerialization < SystemJsonSerializer > ( ) ;
10
- endpointConfiguration . UseTransport < LearningTransport > ( ) ;
10
+ var host = Host . CreateDefaultBuilder ( args )
11
+ . UseConsoleLifetime ( )
12
+ . UseNServiceBus ( _ =>
13
+ {
14
+ var endpointConfiguration = new EndpointConfiguration ( EndpointName ) ;
15
+
16
+ endpointConfiguration . UseSerialization < SystemJsonSerializer > ( ) ;
17
+ endpointConfiguration . UseTransport < LearningTransport > ( ) ;
18
+
19
+ DataDogMetrics . Setup ( endpointConfiguration ) ;
20
+
21
+ return endpointConfiguration ;
22
+ } )
23
+ . Build ( ) ;
11
24
12
- DataDogMetrics . Setup ( endpointConfiguration ) ;
25
+ await host . StartAsync ( ) ;
13
26
14
- var endpointInstance = await Endpoint . Start ( endpointConfiguration ) ;
27
+ var endpointInstance = host . Services . GetRequiredService < IMessageSession > ( ) ;
15
28
16
29
var simulator = new LoadSimulator ( endpointInstance , TimeSpan . Zero , TimeSpan . FromSeconds ( 10 ) ) ;
17
30
await simulator . Start ( ) ;
18
31
19
32
try
20
33
{
21
- Console . WriteLine ( "Endpoint started. Press 'enter' to send a message" ) ;
22
- Console . WriteLine ( "Press ESC key to quit" ) ;
34
+ Console . WriteLine ( "Endpoint started." ) ;
35
+ Console . WriteLine ( "Press [ENTER] to send additional messages." ) ;
36
+ Console . WriteLine ( "Press [Q] to quit." ) ;
23
37
24
38
while ( true )
25
39
{
26
40
var key = Console . ReadKey ( true ) ;
27
- if ( key . Key == ConsoleKey . Escape )
41
+ if ( key . Key == ConsoleKey . Q )
28
42
{
29
43
break ;
30
44
}
35
49
finally
36
50
{
37
51
await simulator . Stop ( ) ;
38
- await endpointInstance . Stop ( ) ;
52
+ await host . StopAsync ( ) ;
39
53
}
0 commit comments