@@ -5,7 +5,7 @@ namespace Client
5
5
using Messages ;
6
6
using NServiceBus ;
7
7
8
- class CommandSender : IWantToRunAtStartup
8
+ public class CommandSender : IWantToRunAtStartup
9
9
{
10
10
public IBus Bus { get ; set ; }
11
11
@@ -14,6 +14,9 @@ public void Run()
14
14
Console . WriteLine ( "Press 'C' to send a command" ) ;
15
15
Console . WriteLine ( "Press 'R' to send a request" ) ;
16
16
Console . WriteLine ( "Press 'S' to start the saga" ) ;
17
+ Console . WriteLine ( "Press 'E' to send a message that is marked as Express" ) ;
18
+ Console . WriteLine ( "Press 'D' to send a large message that is marked to be sent using Data Bus" ) ;
19
+ Console . WriteLine ( "Press 'X' to send a message that is marked with expiration time." ) ;
17
20
Console . WriteLine ( "To exit, press Ctrl + C" ) ;
18
21
19
22
while ( true )
@@ -24,54 +27,102 @@ public void Run()
24
27
case "c" :
25
28
SendCommand ( ) ;
26
29
break ;
30
+
27
31
case "r" :
28
32
SendRequest ( ) ;
29
33
break ;
34
+
30
35
case "s" :
31
36
StartSaga ( ) ;
32
37
break ;
38
+
39
+ case "e" :
40
+ Express ( ) ;
41
+ break ;
42
+
43
+ case "d" :
44
+ Data ( ) ;
45
+ break ;
46
+
47
+ case "x" :
48
+ Expiration ( ) ;
49
+ break ;
33
50
}
34
51
}
35
52
}
36
53
54
+ /// <summary>
55
+ /// Shut down server before sending this message, after 30 seconds, the message will be moved to Transactional dead-letter messages queue.
56
+ /// </summary>
57
+ private void Expiration ( )
58
+ {
59
+ Bus . Send < MessageThatExpires > ( m => m . RequestId = new Guid ( ) ) ;
60
+ Console . WriteLine ( "message with expiration was sent" ) ;
61
+ }
62
+
63
+ private void Data ( )
64
+ {
65
+ var requestId = Guid . NewGuid ( ) ;
66
+
67
+ Bus . Send < LargeMessage > ( m =>
68
+ {
69
+ m . RequestId = requestId ;
70
+ m . LargeDataBus = new byte [ 1024 * 1024 * 5 ] ;
71
+ } ) ;
72
+
73
+ Console . WriteLine ( "Request sent id: " + requestId ) ;
74
+ }
75
+
76
+ private void Express ( )
77
+ {
78
+ var requestId = Guid . NewGuid ( ) ;
79
+
80
+ Bus . Send < RequestExpress > ( m =>
81
+ {
82
+ m . RequestId = requestId ;
83
+ } ) ;
84
+
85
+ Console . WriteLine ( "Request sent id: " + requestId ) ;
86
+ }
87
+
37
88
void StartSaga ( string tennant = "" )
38
89
{
39
90
var message = new StartSagaMessage
40
- {
41
- OrderId = Guid . NewGuid ( )
42
- } ;
91
+ {
92
+ OrderId = Guid . NewGuid ( )
93
+ } ;
43
94
if ( ! string . IsNullOrEmpty ( tennant ) )
44
95
message . SetHeader ( "tennant" , tennant ) ;
45
96
46
97
Bus . Send ( message ) ;
47
- Console . WriteLine ( string . Format ( "{0} - {1}" , DateTime . Now . ToLongTimeString ( ) , "Saga start message sent" ) ) ;
98
+ Console . WriteLine ( "{0} - {1}" , DateTime . Now . ToLongTimeString ( ) , "Saga start message sent" ) ;
48
99
}
49
100
50
101
void SendRequest ( )
51
102
{
52
103
var requestId = Guid . NewGuid ( ) ;
53
104
54
105
Bus . Send < Request > ( m =>
55
- {
56
- m . RequestId = requestId ;
57
- } ) ;
106
+ {
107
+ m . RequestId = requestId ;
108
+ } ) ;
58
109
59
- Console . WriteLine ( "Request sent id: " + requestId ) ;
110
+ Console . WriteLine ( "Request sent id: " + requestId ) ;
60
111
}
61
112
62
113
void SendCommand ( )
63
114
{
64
115
var commandId = Guid . NewGuid ( ) ;
65
116
66
117
Bus . Send < MyCommand > ( m =>
67
- {
68
- m . CommandId = commandId ;
69
- m . EncryptedString = "Some sensitive information" ;
70
- } )
71
- . Register < CommandStatus > ( outcome=> Console . WriteLine ( "Server returned status: " + outcome ) ) ;
118
+ {
119
+ m . CommandId = commandId ;
120
+ m . EncryptedString = "Some sensitive information" ;
121
+ } )
122
+ . Register < CommandStatus > ( outcome => Console . WriteLine ( "Server returned status: " + outcome ) ) ;
72
123
73
124
Console . WriteLine ( "Command sent id: " + commandId ) ;
74
-
125
+
75
126
}
76
127
77
128
public void Stop ( )
0 commit comments