1
+ using Commands ;
2
+ using Messages ;
3
+
4
+ public class CommandSender
5
+ {
6
+ public static async Task Start ( IMessageSession messageSession )
7
+ {
8
+ Console . WriteLine ( "Press 'C' to send a command" ) ;
9
+ Console . WriteLine ( "Press 'R' to send a request" ) ;
10
+ Console . WriteLine ( "Press 'D' to send a large message that is marked to be sent using data bus" ) ;
11
+ Console . WriteLine ( "Press 'X' to send a message that is marked with expiration time." ) ;
12
+ Console . WriteLine ( "Press any other key to exit" ) ;
13
+
14
+ while ( true )
15
+ {
16
+ var key = Console . ReadKey ( ) ;
17
+ Console . WriteLine ( ) ;
18
+
19
+ switch ( key . Key )
20
+ {
21
+ case ConsoleKey . C :
22
+ await SendCommand ( messageSession ) ;
23
+ continue ;
24
+ case ConsoleKey . R :
25
+ await SendRequest ( messageSession ) ;
26
+ continue ;
27
+ case ConsoleKey . D :
28
+ await Data ( messageSession ) ;
29
+ continue ;
30
+ case ConsoleKey . X :
31
+ await Expiration ( messageSession ) ;
32
+ continue ;
33
+ }
34
+ return ;
35
+
36
+ }
37
+ }
38
+
39
+ // Shut down server before sending this message, after 30 seconds, the message will be moved to Transactional dead-letter messages queue.
40
+ static Task Expiration ( IMessageSession messageSession )
41
+ {
42
+ var messageThatExpires = new MessageThatExpires
43
+ {
44
+ RequestId = Guid . NewGuid ( )
45
+ } ;
46
+ Console . WriteLine ( "message with expiration was sent" ) ;
47
+ return messageSession . Send ( "Samples.Unobtrusive.Server" , messageThatExpires ) ;
48
+ }
49
+
50
+ static Task Data ( IMessageSession messageSession )
51
+ {
52
+ var requestId = Guid . NewGuid ( ) ;
53
+
54
+ var largeMessage = new LargeMessage
55
+ {
56
+ RequestId = requestId ,
57
+ LargeClaimCheck = new byte [ 1024 * 1024 * 5 ]
58
+ } ;
59
+ Console . WriteLine ( $ "Request sent id: { requestId } ") ;
60
+ return messageSession . Send ( "Samples.Unobtrusive.Server" , largeMessage ) ;
61
+ }
62
+
63
+ static Task SendRequest ( IMessageSession messageSession )
64
+ {
65
+ var requestId = Guid . NewGuid ( ) ;
66
+
67
+ var request = new Request
68
+ {
69
+ RequestId = requestId
70
+ } ;
71
+ Console . WriteLine ( $ "Request sent id: { requestId } ") ;
72
+ return messageSession . Send ( "Samples.Unobtrusive.Server" , request ) ;
73
+ }
74
+
75
+ static Task SendCommand ( IMessageSession messageSession )
76
+ {
77
+ var commandId = Guid . NewGuid ( ) ;
78
+
79
+ var myCommand = new MyCommand
80
+ {
81
+ CommandId = commandId ,
82
+ } ;
83
+ Console . WriteLine ( $ "Command sent id: { commandId } ") ;
84
+ return messageSession . Send ( "Samples.Unobtrusive.Server" , myCommand ) ;
85
+ }
86
+ }
0 commit comments