Skip to content

Commit ebf2bb6

Browse files
committed
* Movin' stuff around
1 parent b1c3a58 commit ebf2bb6

File tree

8 files changed

+217
-237
lines changed

8 files changed

+217
-237
lines changed

RabbitMQ.AMQP.Client/Impl/ConnectionSettings.cs renamed to RabbitMQ.AMQP.Client/ConnectionSettings.cs

Lines changed: 10 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.Security.Cryptography.X509Certificates;
99
using Amqp;
1010

11-
namespace RabbitMQ.AMQP.Client.Impl
11+
namespace RabbitMQ.AMQP.Client
1212
{
1313
public class ConnectionSettingBuilder
1414
{
@@ -119,17 +119,17 @@ public ConnectionSettings Build()
119119
// <summary>
120120
// Represents a network address.
121121
// </summary>
122-
public class ConnectionSettings : IConnectionSettings
122+
public class ConnectionSettings : IEquatable<ConnectionSettings>
123123
{
124124
private readonly Address _address;
125125
private readonly string _virtualHost = "/";
126126
private readonly string _containerId = "";
127127
private readonly uint _maxFrameSize = Consts.DefaultMaxFrameSize;
128-
private readonly ITlsSettings? _tlsSettings;
128+
private readonly TlsSettings? _tlsSettings;
129129
private readonly SaslMechanism _saslMechanism = SaslMechanism.Plain;
130-
private readonly IRecoveryConfiguration _recoveryConfiguration = RecoveryConfiguration.Create();
130+
private readonly IRecoveryConfiguration _recoveryConfiguration = Impl.RecoveryConfiguration.Create();
131131

132-
public ConnectionSettings(string address, ITlsSettings? tlsSettings = null)
132+
public ConnectionSettings(string address, TlsSettings? tlsSettings = null)
133133
{
134134
_address = new Address(address);
135135
_tlsSettings = tlsSettings;
@@ -146,7 +146,7 @@ public ConnectionSettings(string scheme, string host, int port,
146146
SaslMechanism saslMechanism,
147147
IRecoveryConfiguration recoveryConfiguration,
148148
uint maxFrameSize = Consts.DefaultMaxFrameSize,
149-
ITlsSettings? tlsSettings = null)
149+
TlsSettings? tlsSettings = null)
150150
{
151151
_address = new Address(host: host, port: port,
152152
user: user, password: password,
@@ -183,7 +183,7 @@ public ConnectionSettings(string scheme, string host, int port,
183183
public bool UseSsl => _address.UseSsl;
184184
public uint MaxFrameSize => _maxFrameSize;
185185
public SaslMechanism SaslMechanism => _saslMechanism;
186-
public ITlsSettings? TlsSettings => _tlsSettings;
186+
public TlsSettings? TlsSettings => _tlsSettings;
187187
public IRecoveryConfiguration Recovery => _recoveryConfiguration;
188188

189189
public override string ToString()
@@ -230,14 +230,14 @@ public override int GetHashCode()
230230
return _address.GetHashCode();
231231
}
232232

233-
public bool Equals(IConnectionSettings? other)
233+
bool IEquatable<ConnectionSettings>.Equals(ConnectionSettings? other)
234234
{
235235
if (other is null)
236236
{
237237
return false;
238238
}
239239

240-
if (other is IConnectionSettings connectionSettings)
240+
if (other is ConnectionSettings connectionSettings)
241241
{
242242
return _address.Host == connectionSettings.Host &&
243243
_address.Port == connectionSettings.Port &&
@@ -255,135 +255,7 @@ public bool Equals(IConnectionSettings? other)
255255
// public RecoveryConfiguration RecoveryConfiguration { get; set; } = RecoveryConfiguration.Create();
256256
}
257257

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
387259
{
388260
internal const SslProtocols DefaultSslProtocols = SslProtocols.None;
389261
private readonly X509CertificateCollection _clientCertificates = new X509CertificateCollection();

RabbitMQ.AMQP.Client/Impl/Consts.cs renamed to RabbitMQ.AMQP.Client/Consts.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// and the Mozilla Public License, version 2.0.
33
// Copyright (c) 2017-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
44

5-
namespace RabbitMQ.AMQP.Client.Impl
5+
namespace RabbitMQ.AMQP.Client
66
{
7-
public class Consts
7+
public static class Consts
88
{
99
public const string Exchanges = "exchanges";
1010
public const string Key = "key";

RabbitMQ.AMQP.Client/IConnectionSettings.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
// and the Mozilla Public License, version 2.0.
33
// Copyright (c) 2017-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
44

5+
#if TOOMANYINTERFACES
56
using System;
67
using System.Net.Security;
78
using System.Security.Authentication;
89
using System.Security.Cryptography.X509Certificates;
910

1011
namespace RabbitMQ.AMQP.Client
1112
{
12-
public interface IConnectionSettings : IEquatable<IConnectionSettings>
13+
public interface ConnectionSettings : IEquatable<ConnectionSettings>
1314
{
1415
string Host { get; }
1516
int Port { get; }
@@ -22,14 +23,14 @@ public interface IConnectionSettings : IEquatable<IConnectionSettings>
2223
bool UseSsl { get; }
2324
uint MaxFrameSize { get; }
2425
SaslMechanism SaslMechanism { get; }
25-
ITlsSettings? TlsSettings { get; }
26+
TlsSettings? TlsSettings { get; }
2627
IRecoveryConfiguration Recovery { get; }
2728
}
2829

2930
/// <summary>
3031
/// Contains the TLS/SSL settings for a connection.
3132
/// </summary>
32-
public interface ITlsSettings
33+
public interface TlsSettings
3334
{
3435
/// <summary>
3536
/// Client certificates to use for mutual authentication.
@@ -62,3 +63,4 @@ public interface ITlsSettings
6263
LocalCertificateSelectionCallback? LocalCertificateSelectionCallback { get; set; }
6364
}
6465
}
66+
#endif

RabbitMQ.AMQP.Client/IEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface IEnvironment
1717
/// </summary>
1818
/// <param name="connectionSettings"></param>
1919
/// <returns>IConnection</returns>
20-
public Task<IConnection> CreateConnectionAsync(IConnectionSettings connectionSettings);
20+
public Task<IConnection> CreateConnectionAsync(ConnectionSettings connectionSettings);
2121

2222
/// <summary>
2323
/// Create a new connection with the default connection settings.

RabbitMQ.AMQP.Client/Impl/AmqpConnection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class AmqpConnection : AbstractLifeCycle, IConnection
3434
private readonly AmqpManagement _management;
3535
private readonly RecordingTopologyListener _recordingTopologyListener = new();
3636

37-
internal readonly IConnectionSettings _connectionSettings;
37+
internal readonly ConnectionSettings _connectionSettings;
3838
private readonly IMetricsReporter? _metricsReporter;
3939
internal readonly AmqpSessionManagement _nativePubSubSessions;
4040

@@ -143,7 +143,7 @@ public IEnumerable<IConsumer> Consumers
143143
/// <returns></returns>
144144
// TODO to play nicely with IoC containers, we should not have static Create methods
145145
// TODO rename to CreateAndOpenAsync
146-
public static async Task<IConnection> CreateAsync(IConnectionSettings connectionSettings,
146+
public static async Task<IConnection> CreateAsync(ConnectionSettings connectionSettings,
147147
IMetricsReporter? metricsReporter = default)
148148
{
149149
var connection = new AmqpConnection(connectionSettings, metricsReporter);
@@ -271,7 +271,7 @@ await consumer.CloseAsync()
271271
}
272272
}
273273

274-
private AmqpConnection(IConnectionSettings connectionSettings, IMetricsReporter? metricsReporter)
274+
private AmqpConnection(ConnectionSettings connectionSettings, IMetricsReporter? metricsReporter)
275275
{
276276
_connectionSettings = connectionSettings;
277277
_metricsReporter = metricsReporter;

RabbitMQ.AMQP.Client/Impl/AmqpEnvironment.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ namespace RabbitMQ.AMQP.Client.Impl
1212
{
1313
public class AmqpEnvironment : IEnvironment
1414
{
15-
private IConnectionSettings ConnectionSettings { get; }
15+
private ConnectionSettings ConnectionSettings { get; }
1616
private long _sequentialId = 0;
1717
private readonly ConcurrentDictionary<long, IConnection> _connections = new();
1818
private readonly IMetricsReporter? _metricsReporter;
1919

20-
private AmqpEnvironment(IConnectionSettings connectionSettings, IMetricsReporter? metricsReporter = default)
20+
private AmqpEnvironment(ConnectionSettings connectionSettings, IMetricsReporter? metricsReporter = default)
2121
{
2222
ConnectionSettings = connectionSettings;
2323
_metricsReporter = metricsReporter;
2424
}
2525

2626
// TODO to play nicely with IoC containers, we should not have static Create methods
27-
public static IEnvironment Create(IConnectionSettings connectionSettings, IMetricsReporter? metricsReporter = default)
27+
public static IEnvironment Create(ConnectionSettings connectionSettings, IMetricsReporter? metricsReporter = default)
2828
{
2929
return new AmqpEnvironment(connectionSettings, metricsReporter);
3030
}
3131

32-
public async Task<IConnection> CreateConnectionAsync(IConnectionSettings connectionSettings)
32+
public async Task<IConnection> CreateConnectionAsync(ConnectionSettings connectionSettings)
3333
{
3434
IConnection c = await AmqpConnection.CreateAsync(connectionSettings, _metricsReporter).ConfigureAwait(false);
3535
c.Id = Interlocked.Increment(ref _sequentialId);

0 commit comments

Comments
 (0)