1
- using System ;
2
-
3
- namespace SampleEndpoint
1
+ namespace SampleEndpoint
4
2
{
5
- using System . Threading ;
3
+ using System ;
4
+ using System . Threading . Tasks ;
6
5
using NServiceBus ;
7
- using NServiceBus . Config ;
8
- using NServiceBus . Config . ConfigurationSource ;
9
- using NServiceBus . Metrics . ServiceControl ;
6
+ //using NServiceBus.Logging;
10
7
11
8
class Program
12
9
{
13
- static void Main ( string [ ] args )
10
+ static async Task Main ( string [ ] args )
14
11
{
15
- var config = new BusConfiguration ( ) ;
16
- config . EndpointName ( "SomeName" ) ;
17
- config . SendMetricDataToServiceControl ( "Particular.Monitoring" ) ;
18
- config . UsePersistence < InMemoryPersistence > ( ) ;
12
+ //LogManager.Use<DefaultFactory>().Level(LogLevel.Debug);
19
13
20
- using ( var bus = Bus . Create ( config ) . Start ( ) )
21
- {
22
- Console . WriteLine ( "Bus Started" ) ;
14
+ var endpointConfig = new EndpointConfiguration ( "SomeName" ) ;
15
+ endpointConfig . UseTransport < MsmqTransport > ( ) ;
16
+ endpointConfig . EnableMetrics ( )
17
+ . SendMetricDataToServiceControl ( "Particular.Monitoring" , TimeSpan . FromMilliseconds ( 500 ) ) ;
18
+ endpointConfig . UsePersistence < InMemoryPersistence > ( ) ;
19
+ endpointConfig . AuditProcessedMessagesTo ( "audit" ) ;
20
+ endpointConfig . SendFailedMessagesTo ( "error" ) ;
23
21
24
- while ( Console . ReadKey ( true ) . Key != ConsoleKey . Escape )
25
- {
26
- bus . SendLocal ( new SomeMessage ( ) ) ;
27
- }
22
+ var endpoint = await Endpoint . Start ( endpointConfig ) . ConfigureAwait ( false ) ;
28
23
29
- Console . WriteLine ( "Bus Stopped" ) ;
24
+ Console . WriteLine ( "Endpoint Started" ) ;
25
+
26
+ while ( Console . ReadKey ( true ) . Key != ConsoleKey . Escape )
27
+ {
28
+ await endpoint . SendLocal ( new SomeMessage ( ) ) . ConfigureAwait ( false ) ;
30
29
}
30
+
31
+ await endpoint . Stop ( ) . ConfigureAwait ( false ) ;
32
+
33
+ Console . WriteLine ( "Bus Stopped" ) ;
31
34
}
32
35
}
33
36
@@ -38,27 +41,9 @@ class SomeMessage : ICommand
38
41
39
42
class SomeMessageHandler : IHandleMessages < SomeMessage >
40
43
{
41
- public void Handle ( SomeMessage message )
44
+ public Task Handle ( SomeMessage message , IMessageHandlerContext context )
42
45
{
43
- Thread . Sleep ( TimeSpan . FromMilliseconds ( 500 ) ) ;
46
+ return Task . Delay ( 500 ) ;
44
47
}
45
48
}
46
-
47
-
48
- class AuditConfigProvider : IProvideConfiguration < AuditConfig >
49
- {
50
-
51
- public AuditConfig GetConfiguration ( ) => new AuditConfig
52
- {
53
- QueueName = "audit"
54
- } ;
55
- }
56
-
57
- class ErrorConfigProvider : IProvideConfiguration < MessageForwardingInCaseOfFaultConfig >
58
- {
59
- public MessageForwardingInCaseOfFaultConfig GetConfiguration ( ) => new MessageForwardingInCaseOfFaultConfig
60
- {
61
- ErrorQueue = "error"
62
- } ;
63
- }
64
49
}
0 commit comments