Skip to content

Commit a840f58

Browse files
Merge pull request #178 from rabbitmq/rabbitmq-dotnet-client-176
CreateConnection should select from the provided hostnames
2 parents dfe7b97 + 61a3c68 commit a840f58

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,9 @@ public IConnection CreateConnection(IList<string> hostnames, String clientProvid
419419
else
420420
{
421421
IProtocol protocol = Protocols.DefaultProtocol;
422-
conn = protocol.CreateConnection(this, false, CreateFrameHandler(), clientProvidedName);
422+
var selectedHost = this.HostnameSelector.NextFrom(hostnames);
423+
var endPoint = AmqpTcpEndpoint.Parse(selectedHost);
424+
conn = protocol.CreateConnection(this, false, CreateFrameHandler(endPoint), clientProvidedName);
423425
}
424426
}
425427
catch (Exception e)

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,18 @@ public void TestCreateConnectionParsesHostNameWithPort()
8585
Assert.AreEqual(5672, conn.Endpoint.Port);
8686
}
8787

88+
[Test]
89+
public void TestCreateConnectionWithoutAutoRecoverySelectsAHostFromTheList()
90+
{
91+
var cf = new ConnectionFactory();
92+
cf.AutomaticRecoveryEnabled = false;
93+
cf.HostName = "not_localhost";
94+
cf.Port = 1234;
95+
var conn = cf.CreateConnection(new System.Collections.Generic.List<string> { "localhost" }, "oregano");
96+
conn.Close();
97+
conn.Dispose();
98+
Assert.AreEqual("not_localhost", cf.HostName);
99+
Assert.AreEqual("localhost", conn.Endpoint.HostName);
100+
}
88101
}
89102
}

0 commit comments

Comments
 (0)