@@ -95,7 +95,7 @@ private async Task ReconnectConsumers()
95
95
}
96
96
}
97
97
98
- private readonly ConnectionSettings _connectionSettings ;
98
+ private readonly IConnectionSettings _connectionSettings ;
99
99
internal readonly AmqpSessionManagement _nativePubSubSessions ;
100
100
101
101
// TODO: Implement the semaphore to avoid multiple connections
@@ -116,6 +116,13 @@ public ReadOnlyCollection<IPublisher> GetPublishers()
116
116
return Publishers . Values . ToList ( ) . AsReadOnly ( ) ;
117
117
}
118
118
119
+ public ReadOnlyCollection < IConsumer > GetConsumers ( )
120
+ {
121
+ return Consumers . Values . ToList ( ) . AsReadOnly ( ) ;
122
+ }
123
+
124
+ public long Id { get ; set ; }
125
+
119
126
/// <summary>
120
127
/// Creates a new instance of <see cref="AmqpConnection"/>
121
128
/// Through the Connection is possible to create:
@@ -124,7 +131,7 @@ public ReadOnlyCollection<IPublisher> GetPublishers()
124
131
/// </summary>
125
132
/// <param name="connectionSettings"></param>
126
133
/// <returns></returns>
127
- public static async Task < IConnection > CreateAsync ( ConnectionSettings connectionSettings )
134
+ public static async Task < IConnection > CreateAsync ( IConnectionSettings connectionSettings )
128
135
{
129
136
var connection = new AmqpConnection ( connectionSettings ) ;
130
137
await connection . OpenAsync ( )
@@ -158,7 +165,7 @@ await consumer.CloseAsync()
158
165
}
159
166
}
160
167
161
- private AmqpConnection ( ConnectionSettings connectionSettings )
168
+ private AmqpConnection ( IConnectionSettings connectionSettings )
162
169
{
163
170
_connectionSettings = connectionSettings ;
164
171
_nativePubSubSessions = new AmqpSessionManagement ( this , 1 ) ;
@@ -198,10 +205,7 @@ private async Task EnsureConnection()
198
205
var open = new Open
199
206
{
200
207
HostName = $ "vhost:{ _connectionSettings . VirtualHost } ",
201
- Properties = new Fields ( )
202
- {
203
- [ new Symbol ( "connection_name" ) ] = _connectionSettings . ConnectionName ,
204
- }
208
+ Properties = new Fields ( ) { [ new Symbol ( "connection_name" ) ] = _connectionSettings . ConnectionName , }
205
209
} ;
206
210
207
211
if ( _connectionSettings . MaxFrameSize > uint . MinValue )
@@ -230,12 +234,14 @@ void onOpened(Amqp.IConnection connection, Open open1)
230
234
231
235
if ( _connectionSettings . TlsSettings . LocalCertificateSelectionCallback is not null )
232
236
{
233
- cf . SSL . LocalCertificateSelectionCallback = _connectionSettings . TlsSettings . LocalCertificateSelectionCallback ;
237
+ cf . SSL . LocalCertificateSelectionCallback =
238
+ _connectionSettings . TlsSettings . LocalCertificateSelectionCallback ;
234
239
}
235
240
236
241
if ( _connectionSettings . TlsSettings . RemoteCertificateValidationCallback is not null )
237
242
{
238
- cf . SSL . RemoteCertificateValidationCallback = _connectionSettings . TlsSettings . RemoteCertificateValidationCallback ;
243
+ cf . SSL . RemoteCertificateValidationCallback =
244
+ _connectionSettings . TlsSettings . RemoteCertificateValidationCallback ;
239
245
}
240
246
}
241
247
@@ -246,7 +252,7 @@ void onOpened(Amqp.IConnection connection, Open open1)
246
252
247
253
try
248
254
{
249
- _nativeConnection = await cf . CreateAsync ( _connectionSettings . Address , open : open , onOpened : onOpened )
255
+ _nativeConnection = await cf . CreateAsync ( ( _connectionSettings as ConnectionSettings ) ? . Address , open : open , onOpened : onOpened )
250
256
. ConfigureAwait ( false ) ;
251
257
}
252
258
catch ( Exception ex )
@@ -300,7 +306,7 @@ private ClosedCallback MaybeRecoverConnection()
300
306
// we have to check if the recovery is active.
301
307
// The user may want to disable the recovery mechanism
302
308
// the user can use the lifecycle callback to handle the error
303
- if ( ! _connectionSettings . RecoveryConfiguration . IsActivate ( ) )
309
+ if ( ! _connectionSettings . Recovery . IsActivate ( ) )
304
310
{
305
311
OnNewStatus ( State . Closed , Utils . ConvertError ( error ) ) ;
306
312
ChangeEntitiesStatus ( State . Closed , Utils . ConvertError ( error ) ) ;
@@ -323,19 +329,19 @@ await Task.Run(async () =>
323
329
// the user may want to disable the backoff policy or
324
330
// the backoff policy is not active due of some condition
325
331
// for example: Reaching the maximum number of retries and avoid the forever loop
326
- _connectionSettings . RecoveryConfiguration . GetBackOffDelayPolicy ( ) . IsActive ( ) &&
332
+ _connectionSettings . Recovery . GetBackOffDelayPolicy ( ) . IsActive ( ) &&
327
333
328
334
// even we set the status to reconnecting up, we need to check if the connection is still in the
329
335
// reconnecting status. The user may close the connection in the meanwhile
330
336
State == State . Reconnecting )
331
337
{
332
338
try
333
339
{
334
- int next = _connectionSettings . RecoveryConfiguration . GetBackOffDelayPolicy ( ) . Delay ( ) ;
340
+ int next = _connectionSettings . Recovery . GetBackOffDelayPolicy ( ) . Delay ( ) ;
335
341
336
342
Trace . WriteLine ( TraceLevel . Information ,
337
343
$ "Trying Recovering connection in { next } milliseconds, " +
338
- $ "attempt: { _connectionSettings . RecoveryConfiguration . GetBackOffDelayPolicy ( ) . CurrentAttempt } . " +
344
+ $ "attempt: { _connectionSettings . Recovery . GetBackOffDelayPolicy ( ) . CurrentAttempt } . " +
339
345
$ "Info: { ToString ( ) } )") ;
340
346
341
347
await Task . Delay ( TimeSpan . FromMilliseconds ( next ) )
@@ -352,7 +358,7 @@ await EnsureConnection()
352
358
}
353
359
}
354
360
355
- _connectionSettings . RecoveryConfiguration . GetBackOffDelayPolicy ( ) . Reset ( ) ;
361
+ _connectionSettings . Recovery . GetBackOffDelayPolicy ( ) . Reset ( ) ;
356
362
string connectionDescription = connected ? "recovered" : "not recovered" ;
357
363
Trace . WriteLine ( TraceLevel . Information ,
358
364
$ "Connection { connectionDescription } . Info: { ToString ( ) } ") ;
@@ -362,15 +368,15 @@ await EnsureConnection()
362
368
Trace . WriteLine ( TraceLevel . Verbose , $ "connection is closed. Info: { ToString ( ) } ") ;
363
369
OnNewStatus ( State . Closed ,
364
370
new Error ( ConnectionNotRecoveredCode ,
365
- $ "{ ConnectionNotRecoveredMessage } , recover status: { _connectionSettings . RecoveryConfiguration } ") ) ;
371
+ $ "{ ConnectionNotRecoveredMessage } , recover status: { _connectionSettings . Recovery } ") ) ;
366
372
367
373
ChangeEntitiesStatus ( State . Closed , new Error ( ConnectionNotRecoveredCode ,
368
- $ "{ ConnectionNotRecoveredMessage } , recover status: { _connectionSettings . RecoveryConfiguration } ") ) ;
374
+ $ "{ ConnectionNotRecoveredMessage } , recover status: { _connectionSettings . Recovery } ") ) ;
369
375
370
376
return ;
371
377
}
372
378
373
- if ( _connectionSettings . RecoveryConfiguration . IsTopologyActive ( ) )
379
+ if ( _connectionSettings . Recovery . IsTopologyActive ( ) )
374
380
{
375
381
Trace . WriteLine ( TraceLevel . Information , $ "Recovering topology. Info: { ToString ( ) } ") ;
376
382
var visitor = new Visitor ( _management ) ;
0 commit comments