Skip to content

Commit 6395708

Browse files
committed
introduce Connection Config class
1 parent 9922bc1 commit 6395708

19 files changed

+240
-157
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace RabbitMQ
4+
{
5+
#nullable enable
6+
#if NETSTANDARD
7+
internal static class StringExtension
8+
{
9+
public static bool Contains(this string toSearch, string value, StringComparison comparisonType)
10+
{
11+
return toSearch.IndexOf(value, comparisonType) > 0;
12+
}
13+
}
14+
#endif
15+
}

projects/RabbitMQ.Client/RabbitMQ.Client.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
<Deterministic>true</Deterministic>
3737
</PropertyGroup>
3838

39+
<!-- disable nullable warnings for .NET Standard 2.0 -->
40+
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
41+
<NoWarn>$(NoWarn);nullable</NoWarn>
42+
</PropertyGroup>
43+
3944
<Target Name="SetVersionFromConcourseData" AfterTargets="MinVer" Condition="'$(CONCOURSE_PULL_REQUEST_NUMBER)' != ''">
4045
<PropertyGroup>
4146
<PackageVersion>$(MinVerMajor).$(MinVerMinor).$(MinVerPatch)-$(MinVerPreRelease)-pr.$(CONCOURSE_PULL_REQUEST_NUMBER)</PackageVersion>

projects/RabbitMQ.Client/client/api/ConnectionFactory.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
using System.Reflection;
3737
using System.Security.Authentication;
3838
using System.Text;
39+
using RabbitMQ.Client.client.impl;
3940
using RabbitMQ.Client.Exceptions;
4041
using RabbitMQ.Client.Framing.Impl;
4142
using RabbitMQ.Client.Impl;
@@ -199,7 +200,7 @@ public TimeSpan HandshakeContinuationTimeout
199200
}
200201

201202
/// <summary>
202-
/// Amount of time protocol operations (e.g. <code>queue.declare</code>) are allowed to take before
203+
/// Amount of time protocol operations (e.g. <code>queue.declare</code>) are allowed to take before
203204
/// timing out.
204205
/// </summary>
205206
public TimeSpan ContinuationTimeout
@@ -492,32 +493,47 @@ public IConnection CreateConnection(IList<AmqpTcpEndpoint> endpoints, string cli
492493
/// </exception>
493494
public IConnection CreateConnection(IEndpointResolver endpointResolver, string clientProvidedName)
494495
{
495-
IConnection conn;
496+
ConnectionConfig config = CreateConfig(clientProvidedName);
496497
try
497498
{
498499
if (AutomaticRecoveryEnabled)
499500
{
500-
var autorecoveringConnection = new AutorecoveringConnection(this, clientProvidedName);
501-
autorecoveringConnection.Init(endpointResolver);
502-
conn = autorecoveringConnection;
503-
}
504-
else
505-
{
506-
conn = ((ProtocolBase)Protocols.AMQP_0_9_1).CreateConnection(this, endpointResolver.SelectOne(CreateFrameHandler), clientProvidedName);
501+
return new AutorecoveringConnection(config, endpointResolver);
507502
}
503+
504+
return new Connection(config, endpointResolver.SelectOne(CreateFrameHandler));
508505
}
509506
catch (Exception e)
510507
{
511508
throw new BrokerUnreachableException(e);
512509
}
510+
}
513511

514-
return conn;
512+
private ConnectionConfig CreateConfig(string clientProvidedName)
513+
{
514+
return new ConnectionConfig(
515+
VirtualHost,
516+
UserName,
517+
Password,
518+
AuthMechanisms,
519+
ClientProperties,
520+
clientProvidedName,
521+
RequestedChannelMax,
522+
RequestedFrameMax,
523+
TopologyRecoveryEnabled,
524+
NetworkRecoveryInterval,
525+
RequestedHeartbeat,
526+
ContinuationTimeout,
527+
HandshakeContinuationTimeout,
528+
RequestedConnectionTimeout,
529+
DispatchConsumersAsync,
530+
ConsumerDispatchConcurrency,
531+
CreateFrameHandler);
515532
}
516533

517534
internal IFrameHandler CreateFrameHandler(AmqpTcpEndpoint endpoint)
518535
{
519-
IFrameHandler fh = Protocols.DefaultProtocol.CreateFrameHandler(endpoint, SocketFactory,
520-
RequestedConnectionTimeout, SocketReadTimeout, SocketWriteTimeout);
536+
IFrameHandler fh = new SocketFrameHandler(endpoint, SocketFactory, RequestedConnectionTimeout, SocketReadTimeout, SocketWriteTimeout);
521537
return ConfigureFrameHandler(fh);
522538
}
523539

projects/RabbitMQ.Client/client/api/ExternalMechanism.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
//---------------------------------------------------------------------------
3131

3232
using System;
33+
using RabbitMQ.Client.client.impl;
3334

3435
namespace RabbitMQ.Client
3536
{
@@ -38,7 +39,7 @@ public class ExternalMechanism : IAuthMechanism
3839
/// <summary>
3940
/// Handle one round of challenge-response.
4041
/// </summary>
41-
public byte[] handleChallenge(byte[] challenge, IConnectionFactory factory)
42+
public byte[] handleChallenge(byte[] challenge, ConnectionConfig config)
4243
{
4344
return Array.Empty<byte>();
4445
}

projects/RabbitMQ.Client/client/api/IAuthMechanism.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
3030
//---------------------------------------------------------------------------
3131

32+
using RabbitMQ.Client.client.impl;
33+
3234
namespace RabbitMQ.Client
3335
{
3436
/// <summary>
@@ -39,6 +41,6 @@ public interface IAuthMechanism
3941
/// <summary>
4042
/// Handle one round of challenge-response.
4143
/// </summary>
42-
byte[] handleChallenge(byte[] challenge, IConnectionFactory factory);
44+
byte[] handleChallenge(byte[] challenge, ConnectionConfig config);
4345
}
4446
}

projects/RabbitMQ.Client/client/api/IProtocol.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
3030
//---------------------------------------------------------------------------
3131

32-
using RabbitMQ.Client.Impl;
33-
3432
namespace RabbitMQ.Client
3533
{
3634
/// <summary>

projects/RabbitMQ.Client/client/api/PlainMechanism.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@
3030
//---------------------------------------------------------------------------
3131

3232
using System.Text;
33+
using RabbitMQ.Client.client.impl;
3334

3435
namespace RabbitMQ.Client
3536
{
3637
public class PlainMechanism : IAuthMechanism
3738
{
38-
public byte[] handleChallenge(byte[] challenge, IConnectionFactory factory)
39+
public byte[] handleChallenge(byte[] challenge, ConnectionConfig config)
3940
{
40-
return Encoding.UTF8.GetBytes($"\0{factory.UserName}\0{factory.Password}");
41+
return Encoding.UTF8.GetBytes($"\0{config.UserName}\0{config.Password}");
4142
}
4243
}
4344
}

projects/RabbitMQ.Client/client/framing/Model.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@
3232
using System;
3333
using System.Collections.Generic;
3434
using RabbitMQ.Client.client.framing;
35+
using RabbitMQ.Client.client.impl;
3536
using RabbitMQ.Client.Impl;
3637

3738
namespace RabbitMQ.Client.Framing.Impl
3839
{
3940
internal class Model: ModelBase
4041
{
41-
public Model(bool dispatchAsync, int concurrency, ISession session) : base(dispatchAsync, concurrency, session)
42+
public Model(ConnectionConfig config, ISession session) : base(config, session)
4243
{
4344
}
4445

projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recording.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ internal void DeleteRecordedBinding(in RecordedBinding rb)
176176

177177
internal void RecordConsumer(in RecordedConsumer consumer)
178178
{
179-
if (!_factory.TopologyRecoveryEnabled)
179+
if (!_config.TopologyRecoveryEnabled)
180180
{
181181
return;
182182
}
@@ -189,7 +189,7 @@ internal void RecordConsumer(in RecordedConsumer consumer)
189189

190190
internal void DeleteRecordedConsumer(string consumerTag)
191191
{
192-
if (!_factory.TopologyRecoveryEnabled)
192+
if (!_config.TopologyRecoveryEnabled)
193193
{
194194
return;
195195
}

projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private async Task RecoverConnectionAsync()
7474
bool success;
7575
do
7676
{
77-
await Task.Delay(_factory.NetworkRecoveryInterval, token).ConfigureAwait(false);
77+
await Task.Delay(_config.NetworkRecoveryInterval, token).ConfigureAwait(false);
7878
success = TryPerformAutomaticRecovery();
7979
} while (!success && !token.IsCancellationRequested);
8080
}
@@ -104,7 +104,7 @@ private void StopRecoveryLoop()
104104
}
105105
RecoveryCancellationTokenSource.Cancel();
106106

107-
Task timeout = Task.Delay(_factory.RequestedConnectionTimeout);
107+
Task timeout = Task.Delay(_config.RequestedConnectionTimeout);
108108
if (Task.WhenAny(task, timeout).Result == timeout)
109109
{
110110
ESLog.Warn("Timeout while trying to stop background AutorecoveringConnection recovery loop.");
@@ -133,7 +133,7 @@ private bool TryPerformAutomaticRecovery()
133133
lock (_recordedEntitiesLock)
134134
{
135135
ThrowIfDisposed();
136-
if (_factory.TopologyRecoveryEnabled)
136+
if (_config.TopologyRecoveryEnabled)
137137
{
138138
// The recovery sequence is the following:
139139
//
@@ -171,8 +171,8 @@ private bool TryRecoverConnectionDelegate()
171171
try
172172
{
173173
var defunctConnection = _innerConnection;
174-
IFrameHandler fh = _endpoints.SelectOne(_factory.CreateFrameHandler);
175-
_innerConnection = new Connection(_factory, fh, ClientProvidedName);
174+
IFrameHandler fh = _endpoints.SelectOne(_config.FrameHandlerFactory);
175+
_innerConnection = new Connection(_config, fh);
176176
_innerConnection.TakeOver(defunctConnection);
177177
return true;
178178
}
@@ -290,7 +290,7 @@ private void RecoverModelsAndItsConsumers()
290290
{
291291
foreach (AutorecoveringModel m in _models)
292292
{
293-
m.AutomaticallyRecover(this, _factory.TopologyRecoveryEnabled);
293+
m.AutomaticallyRecover(this, _config.TopologyRecoveryEnabled);
294294
}
295295
}
296296
}

0 commit comments

Comments
 (0)