Skip to content

Commit 3c3827c

Browse files
Merge pull request #331 from rabbitmq/rabbitmq-dotnet-client-330
Reintroduce a Uri property on ConnectionFactory.
2 parents 4e7f35d + 19a62e7 commit 3c3827c

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public class ConnectionFactory : ConnectionFactoryBase, IAsyncConnectionFactory
145145
/// Default SASL auth mechanisms to use.
146146
/// </summary>
147147
public static readonly IList<AuthMechanismFactory> DefaultAuthMechanisms =
148-
new List<AuthMechanismFactory>(){ new PlainMechanismFactory() };
148+
new List<AuthMechanismFactory>() { new PlainMechanismFactory() };
149149

150150
/// <summary>
151151
/// SASL auth mechanisms to use.
@@ -174,6 +174,9 @@ public class ConnectionFactory : ConnectionFactoryBase, IAsyncConnectionFactory
174174
private TimeSpan m_handshakeContinuationTimeout = TimeSpan.FromSeconds(10);
175175
private TimeSpan m_continuationTimeout = TimeSpan.FromSeconds(20);
176176

177+
// just here to hold the value that was set through the setter
178+
private Uri uri;
179+
177180
/// <summary>
178181
/// Amount of time protocol handshake operations are allowed to take before
179182
/// timing out.
@@ -311,6 +314,15 @@ public AmqpTcpEndpoint Endpoint
311314
/// </summary>
312315
public string VirtualHost { get; set; } = DefaultVHost;
313316

317+
/// <summary>
318+
/// Username to use when authenticating to the server.
319+
/// </summary>
320+
public Uri Uri
321+
{
322+
get { return uri; }
323+
set { SetUri(value); }
324+
}
325+
314326
/// <summary>
315327
/// Given a list of mechanism names supported by the server, select a preferred mechanism,
316328
/// or null if we have none in common.
@@ -488,13 +500,13 @@ public IFrameHandler CreateFrameHandlerForHostname(string hostname)
488500
private IFrameHandler ConfigureFrameHandler(IFrameHandler fh)
489501
{
490502
// make sure socket timeouts are higher than heartbeat
491-
fh.ReadTimeout = Math.Max(SocketReadTimeout, RequestedHeartbeat * 1000);
503+
fh.ReadTimeout = Math.Max(SocketReadTimeout, RequestedHeartbeat * 1000);
492504
fh.WriteTimeout = Math.Max(SocketWriteTimeout, RequestedHeartbeat * 1000);
493505
// TODO: add user-provided configurator, like in the Java client
494506
return fh;
495507
}
496508

497-
public void SetUri(Uri uri)
509+
private void SetUri(Uri uri)
498510
{
499511
Endpoint = new AmqpTcpEndpoint();
500512

@@ -554,6 +566,8 @@ that has at least the path segment "/". */
554566
{
555567
VirtualHost = UriDecode(uri.Segments[1]);
556568
}
569+
570+
this.uri = uri;
557571
}
558572

559573
///<summary>
@@ -564,7 +578,7 @@ private static string UriDecode(string uri)
564578
return System.Uri.UnescapeDataString(uri.Replace("+", "%2B"));
565579
}
566580

567-
private List<AmqpTcpEndpoint> LocalEndpoints ()
581+
private List<AmqpTcpEndpoint> LocalEndpoints()
568582
{
569583
return new List<AmqpTcpEndpoint> { this.Endpoint };
570584
}

projects/client/RabbitMQ.Client/src/client/api/IConnectionFactory.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,10 @@ public interface IConnectionFactory
8787
/// </summary>
8888
string VirtualHost { get; set; }
8989

90-
91-
9290
/// <summary>
93-
/// Sets the AMQP Uri to be used for connections.
91+
/// Sets or gets the AMQP Uri to be used for connections.
9492
/// </summary>
95-
void SetUri(Uri uri);
93+
Uri Uri { get; set; }
9694

9795
/// <summary>
9896
/// Given a list of mechanism names supported by the server, select a preferred mechanism,

projects/client/Unit/src/unit/TestAmqpUri.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ private static void AssertUriPartEquivalence(string user, string password, int p
147147
private void ParseFailWith<T>(string uri)
148148
{
149149
var cf = new ConnectionFactory();
150-
Assert.That(() => cf.SetUri(new Uri(uri)), Throws.TypeOf<T>());
150+
Assert.That(() => cf.Uri = new Uri(uri), Throws.TypeOf<T>());
151151
}
152152

153153
private void ParseSuccess(string uri, string user, string password, string host, int port, string vhost)
154154
{
155155
var factory = new ConnectionFactory();
156-
factory.SetUri(new Uri(uri));
156+
factory.Uri = new Uri(uri);
157157
AssertUriPartEquivalence(user, password, port, vhost, factory);
158158
Assert.AreEqual(host, factory.HostName);
159159
}
@@ -162,7 +162,7 @@ private void ParseSuccess(string uri, string user, string password,
162162
string[] hosts, int port, string vhost)
163163
{
164164
var factory = new ConnectionFactory();
165-
factory.SetUri(new Uri(uri));
165+
factory.Uri = new Uri(uri);
166166
AssertUriPartEquivalence(user, password, port, vhost, factory);
167167
Assert.IsTrue((Array.IndexOf(hosts, factory.HostName)) != -1);
168168
}

0 commit comments

Comments
 (0)