Skip to content

Commit b3ba687

Browse files
committed
CreateConnection should select from the provided hostnames when autorecovery is off
1 parent 5ebd32a commit b3ba687

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,19 @@ public void TestProperties()
6868
Assert.AreEqual(cf.HostName, h);
6969
Assert.AreEqual(cf.Port, p);
7070
}
71+
72+
[Test]
73+
public void TestCreateConnectionWithoutAutoRecoverySelectsAHostFromTheList()
74+
{
75+
var cf = new ConnectionFactory();
76+
cf.AutomaticRecoveryEnabled = false;
77+
cf.HostName = "not_localhost";
78+
cf.Port = 1234;
79+
var conn = cf.CreateConnection(new System.Collections.Generic.List<string> { "localhost" }, "oregano");
80+
conn.Close();
81+
conn.Dispose();
82+
Assert.AreEqual("not_localhost", cf.HostName);
83+
Assert.AreEqual("localhost", conn.Endpoint.HostName);
84+
}
7185
}
7286
}

0 commit comments

Comments
 (0)