8
8
using System . Security . Cryptography . X509Certificates ;
9
9
using Amqp ;
10
10
11
- namespace RabbitMQ . AMQP . Client . Impl
11
+ namespace RabbitMQ . AMQP . Client
12
12
{
13
13
public class ConnectionSettingBuilder
14
14
{
@@ -119,17 +119,17 @@ public ConnectionSettings Build()
119
119
// <summary>
120
120
// Represents a network address.
121
121
// </summary>
122
- public class ConnectionSettings : IConnectionSettings
122
+ public class ConnectionSettings : IEquatable < ConnectionSettings >
123
123
{
124
124
private readonly Address _address ;
125
125
private readonly string _virtualHost = "/" ;
126
126
private readonly string _containerId = "" ;
127
127
private readonly uint _maxFrameSize = Consts . DefaultMaxFrameSize ;
128
- private readonly ITlsSettings ? _tlsSettings ;
128
+ private readonly TlsSettings ? _tlsSettings ;
129
129
private readonly SaslMechanism _saslMechanism = SaslMechanism . Plain ;
130
- private readonly IRecoveryConfiguration _recoveryConfiguration = RecoveryConfiguration . Create ( ) ;
130
+ private readonly IRecoveryConfiguration _recoveryConfiguration = Impl . RecoveryConfiguration . Create ( ) ;
131
131
132
- public ConnectionSettings ( string address , ITlsSettings ? tlsSettings = null )
132
+ public ConnectionSettings ( string address , TlsSettings ? tlsSettings = null )
133
133
{
134
134
_address = new Address ( address ) ;
135
135
_tlsSettings = tlsSettings ;
@@ -146,7 +146,7 @@ public ConnectionSettings(string scheme, string host, int port,
146
146
SaslMechanism saslMechanism ,
147
147
IRecoveryConfiguration recoveryConfiguration ,
148
148
uint maxFrameSize = Consts . DefaultMaxFrameSize ,
149
- ITlsSettings ? tlsSettings = null )
149
+ TlsSettings ? tlsSettings = null )
150
150
{
151
151
_address = new Address ( host : host , port : port ,
152
152
user : user , password : password ,
@@ -183,7 +183,7 @@ public ConnectionSettings(string scheme, string host, int port,
183
183
public bool UseSsl => _address . UseSsl ;
184
184
public uint MaxFrameSize => _maxFrameSize ;
185
185
public SaslMechanism SaslMechanism => _saslMechanism ;
186
- public ITlsSettings ? TlsSettings => _tlsSettings ;
186
+ public TlsSettings ? TlsSettings => _tlsSettings ;
187
187
public IRecoveryConfiguration Recovery => _recoveryConfiguration ;
188
188
189
189
public override string ToString ( )
@@ -230,14 +230,14 @@ public override int GetHashCode()
230
230
return _address . GetHashCode ( ) ;
231
231
}
232
232
233
- public bool Equals ( IConnectionSettings ? other )
233
+ bool IEquatable < ConnectionSettings > . Equals ( ConnectionSettings ? other )
234
234
{
235
235
if ( other is null )
236
236
{
237
237
return false ;
238
238
}
239
239
240
- if ( other is IConnectionSettings connectionSettings )
240
+ if ( other is ConnectionSettings connectionSettings )
241
241
{
242
242
return _address . Host == connectionSettings . Host &&
243
243
_address . Port == connectionSettings . Port &&
@@ -255,135 +255,7 @@ public bool Equals(IConnectionSettings? other)
255
255
// public RecoveryConfiguration RecoveryConfiguration { get; set; } = RecoveryConfiguration.Create();
256
256
}
257
257
258
- /// <summary>
259
- /// RecoveryConfiguration is a class that represents the configuration of the recovery of the topology.
260
- /// It is used to configure the recovery of the topology of the server after a connection is established in case of a reconnection
261
- /// The RecoveryConfiguration can be disabled or enabled.
262
- /// If RecoveryConfiguration._active is disabled, the reconnect mechanism will not be activated.
263
- /// If RecoveryConfiguration._topology is disabled, the recovery of the topology will not be activated.
264
- /// </summary>
265
- public class RecoveryConfiguration : IRecoveryConfiguration
266
- {
267
- public static RecoveryConfiguration Create ( )
268
- {
269
- return new RecoveryConfiguration ( ) ;
270
- }
271
-
272
- private RecoveryConfiguration ( )
273
- {
274
- }
275
-
276
- // Activate the reconnect mechanism
277
- private bool _active = true ;
278
-
279
- // Activate the recovery of the topology
280
- private bool _topology = false ;
281
-
282
- private IBackOffDelayPolicy _backOffDelayPolicy = Impl . BackOffDelayPolicy . Create ( ) ;
283
-
284
- public IRecoveryConfiguration Activated ( bool activated )
285
- {
286
- _active = activated ;
287
- return this ;
288
- }
289
-
290
- public bool IsActivate ( )
291
- {
292
- return _active ;
293
- }
294
-
295
- public IRecoveryConfiguration BackOffDelayPolicy ( IBackOffDelayPolicy backOffDelayPolicy )
296
- {
297
- _backOffDelayPolicy = backOffDelayPolicy ;
298
- return this ;
299
- }
300
-
301
- public IBackOffDelayPolicy GetBackOffDelayPolicy ( )
302
- {
303
- return _backOffDelayPolicy ;
304
- }
305
-
306
- public IRecoveryConfiguration Topology ( bool activated )
307
- {
308
- _topology = activated ;
309
- return this ;
310
- }
311
-
312
- public bool IsTopologyActive ( )
313
- {
314
- return _topology ;
315
- }
316
-
317
- public override string ToString ( )
318
- {
319
- return
320
- $ "RecoveryConfiguration{{ Active={ _active } , Topology={ _topology } , BackOffDelayPolicy={ _backOffDelayPolicy } }}";
321
- }
322
- }
323
-
324
- public class BackOffDelayPolicy : IBackOffDelayPolicy
325
- {
326
- public static BackOffDelayPolicy Create ( )
327
- {
328
- return new BackOffDelayPolicy ( ) ;
329
- }
330
-
331
- public static BackOffDelayPolicy Create ( int maxAttempt )
332
- {
333
- return new BackOffDelayPolicy ( maxAttempt ) ;
334
- }
335
-
336
- private BackOffDelayPolicy ( )
337
- {
338
- }
339
-
340
- private BackOffDelayPolicy ( int maxAttempt )
341
- {
342
- _maxAttempt = maxAttempt ;
343
- }
344
-
345
- private const int StartRandomMilliseconds = 500 ;
346
- private const int EndRandomMilliseconds = 1500 ;
347
-
348
- private int _attempt = 1 ;
349
- private readonly int _maxAttempt = 12 ;
350
-
351
- private void ResetAfterMaxAttempt ( )
352
- {
353
- if ( _attempt > 5 )
354
- {
355
- _attempt = 1 ;
356
- }
357
- }
358
-
359
- public int Delay ( )
360
- {
361
- _attempt ++ ;
362
- CurrentAttempt ++ ;
363
- ResetAfterMaxAttempt ( ) ;
364
- return Utils . RandomNext ( StartRandomMilliseconds , EndRandomMilliseconds ) * _attempt ;
365
- }
366
-
367
- public void Reset ( )
368
- {
369
- _attempt = 1 ;
370
- CurrentAttempt = 0 ;
371
- }
372
-
373
- public bool IsActive ( )
374
- {
375
- return CurrentAttempt < _maxAttempt ;
376
- }
377
-
378
- public int CurrentAttempt { get ; private set ; } = 0 ;
379
-
380
- public override string ToString ( )
381
- {
382
- return $ "BackOffDelayPolicy{{ Attempt={ _attempt } , TotalAttempt={ CurrentAttempt } , IsActive={ IsActive ( ) } }}";
383
- }
384
- }
385
-
386
- public class TlsSettings : ITlsSettings
258
+ public class TlsSettings
387
259
{
388
260
internal const SslProtocols DefaultSslProtocols = SslProtocols . None ;
389
261
private readonly X509CertificateCollection _clientCertificates = new X509CertificateCollection ( ) ;
0 commit comments