Skip to content

Commit ae51054

Browse files
author
Matthias Radestock
committed
lots more ways to construct AmqpTcpEndpoint instances
inspired by the ConnectionFactory.CreateConnection overloads
1 parent 0e03573 commit ae51054

File tree

2 files changed

+84
-9
lines changed

2 files changed

+84
-9
lines changed

src/client/api/AmqpTcpEndpoint.cs

Lines changed: 78 additions & 3 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;
@@ -95,13 +103,80 @@ public int Port
95103
///IProtocol, hostname, and port number. If the port number is
96104
///-1, the default port number for the IProtocol will be
97105
///used.</summary>
98-
public AmqpTcpEndpoint(IProtocol protocolVariant, string hostname, int portOrMinusOne)
106+
public AmqpTcpEndpoint(IProtocol protocol, string hostName, int portOrMinusOne)
99107
{
100-
m_protocol = protocolVariant;
101-
m_hostName = hostname;
108+
m_protocol = protocol;
109+
m_hostName = hostName;
102110
m_port = portOrMinusOne;
103111
}
104112

113+
///<summary>Construct an AmqpTcpEndpoint with the given
114+
///IProtocol and hostname, using the default port for the
115+
///IProtocol.</summary>
116+
public AmqpTcpEndpoint(IProtocol protocol, string hostName) :
117+
this(protocol, hostName, -1)
118+
{
119+
}
120+
121+
///<summary>Construct an AmqpTcpEndpoint with the given
122+
///IProtocol, "localhost" as the hostname, and using the
123+
///default port for the IProtocol.</summary>
124+
public AmqpTcpEndpoint(IProtocol protocol) :
125+
this(protocol, "localhost", -1)
126+
{
127+
}
128+
129+
///<summary>Construct an AmqpTcpEndpoint with the given
130+
///hostname and port number, using the IProtocol from
131+
///Protocols.FromEnvironment(). If the port number is
132+
///-1, the default port number for the IProtocol will be
133+
///used.</summary>
134+
public AmqpTcpEndpoint(string hostName, int portOrMinusOne) :
135+
this(Protocols.FromEnvironment(), hostName, portOrMinusOne)
136+
{
137+
}
138+
139+
///<summary>Construct an AmqpTcpEndpoint with the given
140+
///hostname, using the IProtocol from
141+
///Protocols.FromEnvironment(), and the default port number of
142+
///that IProtocol.</summary>
143+
public AmqpTcpEndpoint(string hostName) :
144+
this(Protocols.FromEnvironment(), hostName)
145+
{
146+
}
147+
148+
///<summary>Construct an AmqpTcpEndpoint with a hostname of
149+
///"localhost", using the IProtocol from
150+
///Protocols.FromEnvironment(), and the default port number of
151+
///that IProtocol.</summary>
152+
public AmqpTcpEndpoint() :
153+
this(Protocols.FromEnvironment())
154+
{
155+
}
156+
157+
///<summary>Construct an AmqpTcpEndpoint with the given
158+
///IProtocol and Uri.</summary>
159+
///<remarks>
160+
/// Please see the class overview documentation for
161+
/// information about the Uri format in use.
162+
///</remarks>
163+
public AmqpTcpEndpoint(IProtocol protocol, Uri uri) :
164+
this(protocol, uri.Host, uri.Port)
165+
{
166+
}
167+
168+
///<summary>Construct an AmqpTcpEndpoint with the given
169+
///Uri, using the IProtocol from
170+
///Protocols.FromEnvironment().</summary>
171+
///<remarks>
172+
/// Please see the class overview documentation for
173+
/// information about the Uri format in use.
174+
///</remarks>
175+
public AmqpTcpEndpoint(Uri uri) :
176+
this(Protocols.FromEnvironment(), uri)
177+
{
178+
}
179+
105180
///<summary>Returns a URI-like string of the form
106181
///amqp-PROTOCOL://HOSTNAME:PORTNUMBER</summary>
107182
///<remarks>

src/client/api/ConnectionFactory.cs

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

267267
///<summary>Create a connection to the endpoint specified. The
268268
///port used is the default for the protocol.</summary>
269269
///<exception cref="ArgumentException"/>
270270
public IConnection CreateConnection(IProtocol version, string hostName)
271271
{
272-
return CreateConnection(version, hostName, -1);
272+
return CreateConnection(new AmqpTcpEndpoint(version, hostName));
273273
}
274274

275275
///<summary>Create a connection to the endpoint specified.</summary>
@@ -280,7 +280,7 @@ public IConnection CreateConnection(IProtocol version, string hostName)
280280
///<exception cref="ArgumentException"/>
281281
public IConnection CreateConnection(IProtocol version, Uri uri)
282282
{
283-
return CreateConnection(version, uri.Host, uri.Port);
283+
return CreateConnection(new AmqpTcpEndpoint(version, uri));
284284
}
285285

286286
///<summary>Create a connection to the endpoint specified,
@@ -292,7 +292,7 @@ public IConnection CreateConnection(IProtocol version, Uri uri)
292292
///</remarks>
293293
public IConnection CreateConnection(Uri uri)
294294
{
295-
return CreateConnection(Protocols.FromEnvironment(), uri.Host, uri.Port);
295+
return CreateConnection(new AmqpTcpEndpoint(uri));
296296
}
297297

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

0 commit comments

Comments
 (0)