Skip to content

Commit 27c5a80

Browse files
author
Matthew Sackman
committed
merging in from bug 21531
2 parents a8da523 + 69cc959 commit 27c5a80

File tree

2 files changed

+103
-16
lines changed

2 files changed

+103
-16
lines changed

src/client/api/AmqpTcpEndpoint.cs

Lines changed: 96 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ namespace RabbitMQ.Client
6363
///<summary>Represents a TCP-addressable AMQP peer, including the
6464
///protocol variant to use, and a host name and port
6565
///number.</summary>
66+
///<para>
67+
/// Some of the constructors take, as a convenience, a System.Uri
68+
/// instance representing an AMQP server address. The use of Uri
69+
/// here is not standardised - Uri is simply a convenient
70+
/// container for internet-address-like components. In particular,
71+
/// the Uri "Scheme" property is ignored: only the "Host" and
72+
/// "Port" properties are extracted.
73+
///</para>
6674
public class AmqpTcpEndpoint
6775
{
6876
private IProtocol m_protocol;
@@ -101,25 +109,103 @@ public SslOption Ssl
101109
set { m_ssl = value; }
102110
}
103111

112+
///<summary>Construct an AmqpTcpEndpoint with the given
113+
///IProtocol, hostname, port number and ssl option. If the port
114+
///number is -1, the default port number for the IProtocol
115+
///will be used.</summary>
116+
public AmqpTcpEndpoint(IProtocol protocol, string hostName, int portOrMinusOne, SslOption ssl)
117+
{
118+
m_protocol = protocol;
119+
m_hostName = hostName;
120+
m_port = portOrMinusOne;
121+
m_ssl = ssl;
122+
}
123+
104124
///<summary>Construct an AmqpTcpEndpoint with the given
105125
///IProtocol, hostname, and port number. If the port number is
106126
///-1, the default port number for the IProtocol will be
107127
///used.</summary>
108-
public AmqpTcpEndpoint(IProtocol protocolVariant, string hostname, int portOrMinusOne):
109-
this(protocolVariant, hostname, portOrMinusOne, new SslOption())
128+
public AmqpTcpEndpoint(IProtocol protocol, string hostName, int portOrMinusOne) :
129+
this(protocol, hostName, portOrMinusOne, new SslOption())
110130
{
111131
}
112132

113133
///<summary>Construct an AmqpTcpEndpoint with the given
114-
///IProtocol, hostname, port number and Ssl option. If the port
115-
///number is -1, the default port number for the IProtocol
116-
///will be used.</summary>
117-
public AmqpTcpEndpoint(IProtocol protocolVariant, string hostname, int portOrMinusOne, SslOption ssl)
134+
///IProtocol and hostname, using the default port for the
135+
///IProtocol.</summary>
136+
public AmqpTcpEndpoint(IProtocol protocol, string hostName) :
137+
this(protocol, hostName, -1)
138+
{
139+
}
140+
141+
///<summary>Construct an AmqpTcpEndpoint with the given
142+
///IProtocol, "localhost" as the hostname, and using the
143+
///default port for the IProtocol.</summary>
144+
public AmqpTcpEndpoint(IProtocol protocol) :
145+
this(protocol, "localhost", -1)
146+
{
147+
}
148+
149+
///<summary>Construct an AmqpTcpEndpoint with the given
150+
///hostname and port number, using the IProtocol from
151+
///Protocols.FromEnvironment(). If the port number is
152+
///-1, the default port number for the IProtocol will be
153+
///used.</summary>
154+
public AmqpTcpEndpoint(string hostName, int portOrMinusOne) :
155+
this(Protocols.FromEnvironment(), hostName, portOrMinusOne)
156+
{
157+
}
158+
159+
///<summary>Construct an AmqpTcpEndpoint with the given
160+
///hostname, using the IProtocol from
161+
///Protocols.FromEnvironment(), and the default port number of
162+
///that IProtocol.</summary>
163+
public AmqpTcpEndpoint(string hostName) :
164+
this(Protocols.FromEnvironment(), hostName)
165+
{
166+
}
167+
168+
///<summary>Construct an AmqpTcpEndpoint with a hostname of
169+
///"localhost", using the IProtocol from
170+
///Protocols.FromEnvironment(), and the default port number of
171+
///that IProtocol.</summary>
172+
public AmqpTcpEndpoint() :
173+
this(Protocols.FromEnvironment())
174+
{
175+
}
176+
177+
///<summary>Construct an AmqpTcpEndpoint with the given
178+
///IProtocol, Uri and ssl options.</summary>
179+
///<remarks>
180+
/// Please see the class overview documentation for
181+
/// information about the Uri format in use.
182+
///</remarks>
183+
public AmqpTcpEndpoint(IProtocol protocol, Uri uri, SslOption ssl) :
184+
this(protocol, uri.Host, uri.Port, ssl)
185+
{
186+
}
187+
188+
///<summary>Construct an AmqpTcpEndpoint with the given
189+
///IProtocol and Uri.</summary>
190+
///<remarks>
191+
/// Please see the class overview documentation for
192+
/// information about the Uri format in use.
193+
///</remarks>
194+
public AmqpTcpEndpoint(IProtocol protocol, Uri uri) :
195+
this(protocol, uri.Host, uri.Port)
196+
{
197+
}
198+
199+
///<summary>Construct an AmqpTcpEndpoint with the given
200+
///Uri, using the IProtocol from
201+
///Protocols.FromEnvironment().</summary>
202+
///<remarks>
203+
/// Please see the class overview documentation for
204+
/// information about the Uri format in use.
205+
///</remarks>
206+
public AmqpTcpEndpoint(Uri uri) :
207+
this(Protocols.FromEnvironment(), uri)
118208
{
119-
m_protocol = protocolVariant;
120-
m_hostName = hostname;
121-
m_port = portOrMinusOne;
122-
m_ssl = ssl;
123209
}
124210

125211
///<summary>Returns a URI-like string of the form

src/client/api/ConnectionFactory.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,18 @@ public IConnection CreateConnection(IProtocol version,
259259
string hostName,
260260
int portNumber)
261261
{
262-
return CreateConnection(new AmqpTcpEndpoint[] {
263-
new AmqpTcpEndpoint(version, hostName, portNumber, m_parameters.Ssl)
264-
});
262+
return CreateConnection(new AmqpTcpEndpoint(version,
263+
hostName,
264+
portNumber,
265+
m_parameters.Ssl));
265266
}
266267

267268
///<summary>Create a connection to the endpoint specified. The
268269
///port used is the default for the protocol.</summary>
269270
///<exception cref="ArgumentException"/>
270271
public IConnection CreateConnection(IProtocol version, string hostName)
271272
{
272-
return CreateConnection(version, hostName, -1);
273+
return CreateConnection(new AmqpTcpEndpoint(version, hostName));
273274
}
274275

275276
///<summary>Create a connection to the endpoint specified.</summary>
@@ -280,7 +281,7 @@ public IConnection CreateConnection(IProtocol version, string hostName)
280281
///<exception cref="ArgumentException"/>
281282
public IConnection CreateConnection(IProtocol version, Uri uri)
282283
{
283-
return CreateConnection(version, uri.Host, uri.Port);
284+
return CreateConnection(new AmqpTcpEndpoint(version, uri));
284285
}
285286

286287
///<summary>Create a connection to the endpoint specified,
@@ -292,7 +293,7 @@ public IConnection CreateConnection(IProtocol version, Uri uri)
292293
///</remarks>
293294
public IConnection CreateConnection(Uri uri)
294295
{
295-
return CreateConnection(Protocols.FromEnvironment(), uri.Host, uri.Port);
296+
return CreateConnection(new AmqpTcpEndpoint(uri));
296297
}
297298

298299
///<summary>Create a connection to the host (and optional

0 commit comments

Comments
 (0)