@@ -52,18 +52,28 @@ protected override Task OnCancelAsync(string[] consumerTags, CancellationToken c
52
52
53
53
static class Program
54
54
{
55
+ const string DefaultHostName = "localhost" ;
55
56
const string ConnectionClientProvidedName = "GH_1749" ;
56
-
57
- static readonly Util s_util = new ( ) ;
58
57
static readonly CancellationTokenSource s_cancellationTokenSource = new ( ) ;
59
58
static readonly CancellationToken s_cancellationToken = s_cancellationTokenSource . Token ;
60
59
60
+ static Util ? s_util ;
61
+
61
62
static async Task Main ( string [ ] args )
62
63
{
64
+ string hostname = DefaultHostName ;
65
+ if ( args . Length > 0 )
66
+ {
67
+ hostname = args [ 0 ] ;
68
+ }
69
+
70
+ s_util = new Util ( hostname , "guest" , "guest" ) ;
71
+
63
72
AppDomain . CurrentDomain . FirstChanceException += CurrentDomain_FirstChanceException ;
64
73
65
74
ConnectionFactory connectionFactory = new ( )
66
75
{
76
+ HostName = hostname ,
67
77
AutomaticRecoveryEnabled = true ,
68
78
UserName = "guest" ,
69
79
Password = "guest" ,
@@ -87,9 +97,10 @@ static async Task Main(string[] args)
87
97
88
98
connection . ConnectionRecoveryErrorAsync += Connection_ConnectionRecoveryErrorAsync ;
89
99
90
- connection . ConnectionShutdownAsync += async ( object sender , ShutdownEventArgs ea ) =>
100
+ connection . ConnectionShutdownAsync += ( object sender , ShutdownEventArgs ea ) =>
91
101
{
92
102
Console . WriteLine ( "{0} [INFO] saw ConnectionShutdownAsync, event: {1}" , Now , ea ) ;
103
+ return Task . CompletedTask ;
93
104
} ;
94
105
95
106
connection . ConsumerTagChangeAfterRecoveryAsync += Connection_ConsumerTagChangeAfterRecoveryAsync ;
@@ -99,6 +110,9 @@ static async Task Main(string[] args)
99
110
100
111
await using var channel = await connection . CreateChannelAsync ( options : channelOptions ) ;
101
112
113
+ channel . CallbackExceptionAsync += Channel_CallbackExceptionAsync ;
114
+ channel . ChannelShutdownAsync += Channel_ChannelShutdownAsync ;
115
+
102
116
QueueDeclareOk queue = await channel . QueueDeclareAsync ( ) ;
103
117
104
118
var consumer = new GH1749Consumer ( channel ) ;
@@ -112,6 +126,11 @@ static async Task Main(string[] args)
112
126
113
127
static async Task CloseConnectionAsync ( )
114
128
{
129
+ if ( s_util is null )
130
+ {
131
+ throw new NullReferenceException ( "s_util" ) ;
132
+ }
133
+
115
134
try
116
135
{
117
136
Console . WriteLine ( "{0} [INFO] start closing connection: {1}" , Now , ConnectionClientProvidedName ) ;
@@ -126,16 +145,31 @@ static async Task CloseConnectionAsync()
126
145
127
146
private static string Now => Util . Now ;
128
147
129
- private static void CurrentDomain_FirstChanceException ( object ? sender , FirstChanceExceptionEventArgs e )
148
+ private static Task Channel_CallbackExceptionAsync ( object sender , CallbackExceptionEventArgs ea )
149
+ {
150
+ Console . WriteLine ( "{0} [INFO] channel saw CallbackExceptionAsync, event: {1}" , Now , ea ) ;
151
+ Console . WriteLine ( "{0} [INFO] channel CallbackExceptionAsync, exception: {1}" , Now , ea . Exception ) ;
152
+ return Task . CompletedTask ;
153
+ }
154
+
155
+ private static Task Channel_ChannelShutdownAsync ( object sender , ShutdownEventArgs ea )
130
156
{
131
- Console . WriteLine ( "{0} [INFO] saw FirstChanceException, exception: {1}" , Now , e . Exception ) ;
157
+ Console . WriteLine ( "{0} [INFO] saw ChannelShutdownAsync, event: {1}" , Now , ea ) ;
158
+ return Task . CompletedTask ;
132
159
}
133
160
161
+ private static void CurrentDomain_FirstChanceException ( object ? sender , FirstChanceExceptionEventArgs e )
162
+ {
163
+ if ( e . Exception is ObjectDisposedException )
164
+ {
165
+ Console . WriteLine ( "{0} [INFO] saw FirstChanceException, exception: {1}" , Now , e . Exception ) ;
166
+ }
167
+ }
134
168
135
169
private static Task Connection_CallbackExceptionAsync ( object sender , CallbackExceptionEventArgs ea )
136
170
{
137
- Console . WriteLine ( "{0} [INFO] saw CallbackExceptionAsync, event: {1}" , Now , ea ) ;
138
- Console . WriteLine ( "{0} [INFO] CallbackExceptionAsync, exception: {1}" , Now , ea . Exception ) ;
171
+ Console . WriteLine ( "{0} [INFO] connection saw CallbackExceptionAsync, event: {1}" , Now , ea ) ;
172
+ Console . WriteLine ( "{0} [INFO] connection CallbackExceptionAsync, exception: {1}" , Now , ea . Exception ) ;
139
173
return Task . CompletedTask ;
140
174
}
141
175
0 commit comments