@@ -95,7 +95,7 @@ private async Task ReconnectConsumers()
9595 }
9696 }
9797
98- private readonly ConnectionSettings _connectionSettings ;
98+ private readonly IConnectionSettings _connectionSettings ;
9999 internal readonly AmqpSessionManagement _nativePubSubSessions ;
100100
101101 // TODO: Implement the semaphore to avoid multiple connections
@@ -116,6 +116,13 @@ public ReadOnlyCollection<IPublisher> GetPublishers()
116116 return Publishers . Values . ToList ( ) . AsReadOnly ( ) ;
117117 }
118118
119+ public ReadOnlyCollection < IConsumer > GetConsumers ( )
120+ {
121+ return Consumers . Values . ToList ( ) . AsReadOnly ( ) ;
122+ }
123+
124+ public long Id { get ; set ; }
125+
119126 /// <summary>
120127 /// Creates a new instance of <see cref="AmqpConnection"/>
121128 /// Through the Connection is possible to create:
@@ -124,7 +131,7 @@ public ReadOnlyCollection<IPublisher> GetPublishers()
124131 /// </summary>
125132 /// <param name="connectionSettings"></param>
126133 /// <returns></returns>
127- public static async Task < IConnection > CreateAsync ( ConnectionSettings connectionSettings )
134+ public static async Task < IConnection > CreateAsync ( IConnectionSettings connectionSettings )
128135 {
129136 var connection = new AmqpConnection ( connectionSettings ) ;
130137 await connection . OpenAsync ( )
@@ -158,7 +165,7 @@ await consumer.CloseAsync()
158165 }
159166 }
160167
161- private AmqpConnection ( ConnectionSettings connectionSettings )
168+ private AmqpConnection ( IConnectionSettings connectionSettings )
162169 {
163170 _connectionSettings = connectionSettings ;
164171 _nativePubSubSessions = new AmqpSessionManagement ( this , 1 ) ;
@@ -198,10 +205,7 @@ private async Task EnsureConnection()
198205 var open = new Open
199206 {
200207 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 , }
205209 } ;
206210
207211 void onOpened ( Amqp . IConnection connection , Open open1 )
@@ -224,12 +228,14 @@ void onOpened(Amqp.IConnection connection, Open open1)
224228
225229 if ( _connectionSettings . TlsSettings . LocalCertificateSelectionCallback is not null )
226230 {
227- cf . SSL . LocalCertificateSelectionCallback = _connectionSettings . TlsSettings . LocalCertificateSelectionCallback ;
231+ cf . SSL . LocalCertificateSelectionCallback =
232+ _connectionSettings . TlsSettings . LocalCertificateSelectionCallback ;
228233 }
229234
230235 if ( _connectionSettings . TlsSettings . RemoteCertificateValidationCallback is not null )
231236 {
232- cf . SSL . RemoteCertificateValidationCallback = _connectionSettings . TlsSettings . RemoteCertificateValidationCallback ;
237+ cf . SSL . RemoteCertificateValidationCallback =
238+ _connectionSettings . TlsSettings . RemoteCertificateValidationCallback ;
233239 }
234240 }
235241
@@ -240,7 +246,7 @@ void onOpened(Amqp.IConnection connection, Open open1)
240246
241247 try
242248 {
243- _nativeConnection = await cf . CreateAsync ( _connectionSettings . Address , open : open , onOpened : onOpened )
249+ _nativeConnection = await cf . CreateAsync ( ( _connectionSettings as ConnectionSettings ) ? . Address , open : open , onOpened : onOpened )
244250 . ConfigureAwait ( false ) ;
245251 }
246252 catch ( Exception ex )
@@ -294,7 +300,7 @@ private ClosedCallback MaybeRecoverConnection()
294300 // we have to check if the recovery is active.
295301 // The user may want to disable the recovery mechanism
296302 // the user can use the lifecycle callback to handle the error
297- if ( ! _connectionSettings . RecoveryConfiguration . IsActivate ( ) )
303+ if ( ! _connectionSettings . Recovery . IsActivate ( ) )
298304 {
299305 OnNewStatus ( State . Closed , Utils . ConvertError ( error ) ) ;
300306 ChangeEntitiesStatus ( State . Closed , Utils . ConvertError ( error ) ) ;
@@ -317,19 +323,19 @@ await Task.Run(async () =>
317323 // the user may want to disable the backoff policy or
318324 // the backoff policy is not active due of some condition
319325 // for example: Reaching the maximum number of retries and avoid the forever loop
320- _connectionSettings . RecoveryConfiguration . GetBackOffDelayPolicy ( ) . IsActive ( ) &&
326+ _connectionSettings . Recovery . GetBackOffDelayPolicy ( ) . IsActive ( ) &&
321327
322328 // even we set the status to reconnecting up, we need to check if the connection is still in the
323329 // reconnecting status. The user may close the connection in the meanwhile
324330 State == State . Reconnecting )
325331 {
326332 try
327333 {
328- int next = _connectionSettings . RecoveryConfiguration . GetBackOffDelayPolicy ( ) . Delay ( ) ;
334+ int next = _connectionSettings . Recovery . GetBackOffDelayPolicy ( ) . Delay ( ) ;
329335
330336 Trace . WriteLine ( TraceLevel . Information ,
331337 $ "Trying Recovering connection in { next } milliseconds, " +
332- $ "attempt: { _connectionSettings . RecoveryConfiguration . GetBackOffDelayPolicy ( ) . CurrentAttempt } . " +
338+ $ "attempt: { _connectionSettings . Recovery . GetBackOffDelayPolicy ( ) . CurrentAttempt } . " +
333339 $ "Info: { ToString ( ) } )") ;
334340
335341 await Task . Delay ( TimeSpan . FromMilliseconds ( next ) )
@@ -346,7 +352,7 @@ await EnsureConnection()
346352 }
347353 }
348354
349- _connectionSettings . RecoveryConfiguration . GetBackOffDelayPolicy ( ) . Reset ( ) ;
355+ _connectionSettings . Recovery . GetBackOffDelayPolicy ( ) . Reset ( ) ;
350356 string connectionDescription = connected ? "recovered" : "not recovered" ;
351357 Trace . WriteLine ( TraceLevel . Information ,
352358 $ "Connection { connectionDescription } . Info: { ToString ( ) } ") ;
@@ -356,15 +362,15 @@ await EnsureConnection()
356362 Trace . WriteLine ( TraceLevel . Verbose , $ "connection is closed. Info: { ToString ( ) } ") ;
357363 OnNewStatus ( State . Closed ,
358364 new Error ( ConnectionNotRecoveredCode ,
359- $ "{ ConnectionNotRecoveredMessage } , recover status: { _connectionSettings . RecoveryConfiguration } ") ) ;
365+ $ "{ ConnectionNotRecoveredMessage } , recover status: { _connectionSettings . Recovery } ") ) ;
360366
361367 ChangeEntitiesStatus ( State . Closed , new Error ( ConnectionNotRecoveredCode ,
362- $ "{ ConnectionNotRecoveredMessage } , recover status: { _connectionSettings . RecoveryConfiguration } ") ) ;
368+ $ "{ ConnectionNotRecoveredMessage } , recover status: { _connectionSettings . Recovery } ") ) ;
363369
364370 return ;
365371 }
366372
367- if ( _connectionSettings . RecoveryConfiguration . IsTopologyActive ( ) )
373+ if ( _connectionSettings . Recovery . IsTopologyActive ( ) )
368374 {
369375 Trace . WriteLine ( TraceLevel . Information , $ "Recovering topology. Info: { ToString ( ) } ") ;
370376 var visitor = new Visitor ( _management ) ;
0 commit comments