File tree Expand file tree Collapse file tree 6 files changed +34
-43
lines changed
samples/azure/storage-queues/ASQN_13 Expand file tree Collapse file tree 6 files changed +34
-43
lines changed Original file line number Diff line number Diff line change 1
1
using System . Threading . Tasks ;
2
2
using NServiceBus ;
3
3
using Microsoft . Extensions . Logging ;
4
+ using Shared ;
4
5
5
6
public sealed class Endpoint2ResponseHandler ( ILogger < Endpoint2ResponseHandler > logger )
6
- : IHandleMessages < Endpoint2 . MyResponse >
7
+ : IHandleMessages < MyResponse >
7
8
{
8
- public Task Handle ( Endpoint2 . MyResponse message , IMessageHandlerContext context )
9
+ public Task Handle ( MyResponse message , IMessageHandlerContext context )
9
10
{
10
11
logger . LogInformation ( "Received MyResponse: {Property}" , message . Property ) ;
11
12
return Task . CompletedTask ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
using System ;
2
- using Endpoint1 ;
3
2
using Microsoft . Extensions . DependencyInjection ;
4
3
using Microsoft . Extensions . Hosting ;
5
4
using NServiceBus ;
5
+ using Shared ;
6
6
7
7
var host = Host . CreateDefaultBuilder ( args )
8
- . ConfigureServices ( ( hostContext , services ) => { services . AddHostedService < InputLoopService > ( ) ; } )
9
8
. UseNServiceBus ( x =>
10
9
{
11
10
#region endpointName
21
20
22
21
var transport = new AzureStorageQueueTransport ( "UseDevelopmentStorage=true" ) ;
23
22
var routingSettings = endpointConfiguration . UseTransport ( transport ) ;
24
- routingSettings . RouteToEndpoint ( typeof ( Endpoint2 . MyRequest ) , "Samples-Azure-StorageQueues-Endpoint2" ) ;
23
+ routingSettings . RouteToEndpoint ( typeof ( MyRequest ) , "Samples-Azure-StorageQueues-Endpoint2" ) ;
25
24
26
25
#endregion
27
26
39
38
return endpointConfiguration ;
40
39
} ) . Build ( ) ;
41
40
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 ( ) ;
Original file line number Diff line number Diff line change 1
1
using System . Threading . Tasks ;
2
2
using NServiceBus ;
3
3
using Microsoft . Extensions . Logging ;
4
+ using Shared ;
4
5
5
6
public sealed class MyRequestResponseHandler ( ILogger < MyRequestResponseHandler > logger )
6
- : IHandleMessages < Endpoint2 . MyRequest >
7
+ : IHandleMessages < MyRequest >
7
8
{
8
- public Task Handle ( Endpoint2 . MyRequest message , IMessageHandlerContext context )
9
+ public Task Handle ( MyRequest message , IMessageHandlerContext context )
9
10
{
10
11
logger . LogInformation ( "Received MyRequest: {Property}" , message . Property ) ;
11
- var myResponse = new Endpoint2 . MyResponse ( "Hello from Endpoint2" ) ;
12
+ var myResponse = new MyResponse ( "Hello from Endpoint2" ) ;
12
13
return context . Reply ( myResponse ) ;
13
14
}
14
15
}
Original file line number Diff line number Diff line change 1
1
using NServiceBus ;
2
2
3
- namespace Endpoint2 ;
3
+ namespace Shared ;
4
4
5
5
public record MyRequest ( string Property ) : IMessage ;
Original file line number Diff line number Diff line change 1
1
using NServiceBus ;
2
2
3
- namespace Endpoint2 ;
3
+ namespace Shared ;
4
4
5
5
public record MyResponse ( string Property ) : IMessage ;
You can’t perform that action at this time.
0 commit comments