Skip to content

Commit 91968b9

Browse files
author
David R. MacIver
committed
fix default port handling
1 parent 349c5f0 commit 91968b9

File tree

7 files changed

+27
-35
lines changed

7 files changed

+27
-35
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,19 @@ public string HostName
8181
set { m_hostName = value; }
8282
}
8383

84+
85+
public const int DEFAULT_PORT = 5672;
86+
public const int DEFAULT_SSL_PORT = 5671;
87+
88+
89+
8490
private int m_port;
8591
///<summary>Retrieve or set the port number of this
8692
///AmqpTcpEndpoint. -1 indicates the default value should be used.
8793
///</summary>
8894
public int Port
8995
{
90-
get { return m_port; }
96+
get { return m_port == -1 ? (Ssl.Enabled ? DEFAULT_SSL_PORT : DEFAULT_PORT ) : m_port; }
9197
set { m_port = value; }
9298
}
9399

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,5 @@ public ConnectionParameters(AMQPParameters amqp, AmqpTcpEndpoint tcp){
7373
public ConnectionParameters() : this(new AMQPParameters(), new AmqpTcpEndpoint()){
7474
}
7575

76-
// TODO: This should really be part of the protocol, but it's unlikely to change
77-
// and has this value in all versions we support.
78-
public const int DEFAULT_SSL_PORT = 5671;
79-
80-
81-
public int Port{
82-
get{
83-
if(TCP.Port == -1){
84-
return TCP.Ssl.Enabled ? DEFAULT_SSL_PORT : AMQP.Protocol.DefaultPort;
85-
} else {
86-
return TCP.Port;
87-
}
88-
}
89-
}
9076
}
9177
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public interface IProtocol
7474
int DefaultPort { get; }
7575

7676
///<summary>Construct a frame handler for a given endpoint.</summary>
77-
IFrameHandler CreateFrameHandler(AmqpTcpEndpoint endpoint);
77+
IFrameHandler CreateFrameHandler(AmqpTcpEndpoint parameters);
7878
///<summary>Construct a connection from a given set of
7979
///parameters and a frame handler. The "insist" parameter is
8080
///passed on to the AMQP connection.open method.</summary>

projects/client/RabbitMQ.Client/src/client/impl/v0_8qpid/ProtocolBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ namespace RabbitMQ.Client.Framing.Impl.v0_8qpid {
6262
public abstract class ProtocolBase: AbstractProtocolBase {
6363

6464
public override IFrameHandler CreateFrameHandler(AmqpTcpEndpoint endpoint) {
65-
//TODO: Query why we are creating a 0.9 frame handler for a 0.8 protocol
6665
return new SocketFrameHandler_0_9(this, endpoint);
6766
}
6867

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@
6363
public class TestSsl {
6464

6565
public void SendReceive(ConnectionFactory cf) {
66-
IProtocol proto = Protocols.DefaultProtocol;
67-
using (IConnection conn = cf.CreateConnection(proto, "localhost", 5671)) {
66+
using (IConnection conn = cf.CreateConnection()) {
6867
IModel ch = conn.CreateModel();
6968

7069
ch.ExchangeDeclare("Exchange_TestSslEndPoint", ExchangeType.Direct);
@@ -88,11 +87,12 @@ public void SendReceive(ConnectionFactory cf) {
8887
public void TestServerVerifiedIgnoringNameMismatch() {
8988
string sslDir = Environment.GetEnvironmentVariable("SSL_CERTS_DIR");
9089
if (null == sslDir) return;
91-
92-
ConnectionFactory cf = new ConnectionFactory();
93-
cf.Parameters.Ssl.ServerName = "*";
94-
cf.Parameters.Ssl.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch;
95-
cf.Parameters.Ssl.Enabled = true;
90+
91+
AmqpTcpEndpoint endpoint = new AmqpTcpEndpoint();
92+
endpoint.Ssl.ServerName = "*";
93+
endpoint.Ssl.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch;
94+
endpoint.Ssl.Enabled = true;
95+
ConnectionFactory cf = new ConnectionFactory(endpoint);
9696
SendReceive(cf);
9797
}
9898

@@ -101,9 +101,10 @@ public void TestServerVerified() {
101101
string sslDir = Environment.GetEnvironmentVariable("SSL_CERTS_DIR");
102102
if (null == sslDir) return;
103103

104-
ConnectionFactory cf = new ConnectionFactory();
105-
cf.Parameters.Ssl.ServerName = System.Net.Dns.GetHostName();
106-
cf.Parameters.Ssl.Enabled = true;
104+
AmqpTcpEndpoint endpoint = new AmqpTcpEndpoint();
105+
endpoint.Ssl.ServerName = System.Net.Dns.GetHostName();
106+
endpoint.Ssl.Enabled = true;
107+
ConnectionFactory cf = new ConnectionFactory(endpoint);
107108
SendReceive(cf);
108109
}
109110

@@ -112,14 +113,14 @@ public void TestClientAndServerVerified() {
112113
string sslDir = Environment.GetEnvironmentVariable("SSL_CERTS_DIR");
113114
if (null == sslDir) return;
114115

115-
ConnectionFactory cf = new ConnectionFactory();
116-
cf.Parameters.Ssl.ServerName = System.Net.Dns.GetHostName();
117-
Assert.IsNotNull(sslDir);
118-
cf.Parameters.Ssl.CertPath = sslDir + "/client/keycert.p12";
116+
AmqpTcpEndpoint endpoint = new AmqpTcpEndpoint();
117+
endpoint.Ssl.ServerName = System.Net.Dns.GetHostName();
118+
endpoint.Ssl.CertPath = sslDir + "/client/keycert.p12";
119119
string p12Password = Environment.GetEnvironmentVariable("PASSWORD");
120120
Assert.IsNotNull(p12Password, "missing PASSWORD env var");
121-
cf.Parameters.Ssl.CertPassphrase = p12Password;
122-
cf.Parameters.Ssl.Enabled = true;
121+
endpoint.Ssl.CertPassphrase = p12Password;
122+
endpoint.Ssl.Enabled = true;
123+
ConnectionFactory cf = new ConnectionFactory(endpoint);
123124
SendReceive(cf);
124125
}
125126
}

projects/examples/client/AddClient/src/examples/AddClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static int Main(string[] args) {
7171
return 2;
7272
}
7373

74-
using (IConnection conn = new ConnectionFactory().CreateConnection(args[0])) {
74+
using (IConnection conn = new ConnectionFactory(AmqpTcpEndpoint.Parse(args[0])).CreateConnection()) {
7575
using (IModel ch = conn.CreateModel()) {
7676

7777
object[] addends = new object[args.Length - 1];

projects/examples/client/AddServer/src/examples/AddServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static int Main(string[] args) {
7272
return 2;
7373
}
7474

75-
using (IConnection conn = new ConnectionFactory().CreateConnection(args[0])) {
75+
using (IConnection conn = new ConnectionFactory(AmqpTcpEndpoint.Parse(args[0])).CreateConnection()) {
7676
using (IModel ch = conn.CreateModel()) {
7777
Subscription sub = new Subscription(ch, "AddServer");
7878
new AddServer(sub).MainLoop();

0 commit comments

Comments
 (0)