Skip to content

Commit bf25f56

Browse files
author
Matthew Sackman
committed
Merging bug 21899 into default
2 parents 4364545 + c1451ef commit bf25f56

File tree

29 files changed

+256
-210
lines changed

29 files changed

+256
-210
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ namespace RabbitMQ.Client
7373
///</para>
7474
public class AmqpTcpEndpoint
7575
{
76+
///<summary>Indicates that the default port for the protocol should be used</summary>
77+
public const int UseDefaultPort = -1;
78+
7679
private IProtocol m_protocol;
7780
///<summary>Retrieve or set the IProtocol of this AmqpTcpEndpoint.</summary>
7881
public IProtocol Protocol
@@ -95,7 +98,7 @@ public string HostName
9598
///port number for the IProtocol to be used.</summary>
9699
public int Port
97100
{
98-
get { return (m_port == -1) ? m_protocol.DefaultPort : m_port; }
101+
get { return (m_port == UseDefaultPort) ? m_protocol.DefaultPort : m_port; }
99102
set { m_port = value; }
100103
}
101104

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

Lines changed: 97 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ namespace RabbitMQ.Client
7474
///<example><code>
7575
/// ConnectionFactory factory = new ConnectionFactory();
7676
/// //
77-
/// // The next three lines are optional:
78-
/// factory.Parameters.UserName = ConnectionParameters.DefaultUser;
79-
/// factory.Parameters.Password = ConnectionParameters.DefaultPass;
80-
/// factory.Parameters.VirtualHost = ConnectionParameters.DefaultVHost;
77+
/// // The next six lines are optional:
78+
/// factory.UserName = ConnectionFactory.DefaultUser;
79+
/// factory.Password = ConnectionFactory.DefaultPass;
80+
/// factory.VirtualHost = ConnectionFactory.DefaultVHost;
81+
/// factory.Protocol = Protocols.FromEnvironment();
82+
/// factory.HostName = hostName;
83+
// factory.PortNumber = AmqpTcpEndpoint.UseDefaultPort;
8184
/// //
82-
/// IProtocol protocol = Protocols.DefaultProtocol;
83-
/// IConnection conn = factory.CreateConnection(protocol, hostName, portNumber);
85+
/// IConnection conn = factory.CreateConnection();
8486
/// //
8587
/// IModel ch = conn.CreateModel();
8688
/// //
@@ -103,23 +105,93 @@ namespace RabbitMQ.Client
103105
///</remarks>
104106
public class ConnectionFactory
105107
{
106-
private ConnectionParameters m_parameters = new ConnectionParameters();
107-
///<summary>Retrieve the parameters this factory uses to
108-
///construct IConnection instances.</summary>
109-
public ConnectionParameters Parameters
110-
{
111-
get
112-
{
113-
return m_parameters;
114-
}
108+
/// <summary>Default user name (value: "guest")</summary>
109+
public const string DefaultUser = "guest"; // PLEASE KEEP THIS MATCHING THE DOC ABOVE
110+
111+
/// <summary>Default password (value: "guest")</summary>
112+
public const string DefaultPass = "guest"; // PLEASE KEEP THIS MATCHING THE DOC ABOVE
113+
114+
/// <summary>Default virtual host (value: "/")</summary>
115+
public const string DefaultVHost = "/"; // PLEASE KEEP THIS MATCHING THE DOC ABOVE
116+
117+
/// <summary> Default value for the desired maximum channel
118+
/// number, with zero meaning unlimited (value: 0)</summary>
119+
public const ushort DefaultChannelMax = 0; // PLEASE KEEP THIS MATCHING THE DOC ABOVE
120+
121+
/// <summary>Default value for the desired maximum frame size,
122+
/// with zero meaning unlimited (value: 0)</summary>
123+
public const uint DefaultFrameMax = 0; // PLEASE KEEP THIS MATCHING THE DOC ABOVE
124+
125+
/// <summary>Default value for desired heartbeat interval, in
126+
/// seconds, with zero meaning none (value: 0)</summary>
127+
public const ushort DefaultHeartbeat = 0; // PLEASE KEEP THIS MATCHING THE DOC ABOVE
128+
129+
/// <summary>Username to use when authenticating to the server</summary>
130+
public string UserName = DefaultUser;
131+
132+
/// <summary>Password to use when authenticating to the server</summary>
133+
public string Password = DefaultPass;
134+
135+
/// <summary>Virtual host to access during this connection</summary>
136+
public string VirtualHost = DefaultVHost;
137+
138+
/// <summary>Maximum channel number to ask for</summary>
139+
public ushort RequestedChannelMax = DefaultChannelMax;
140+
141+
/// <summary>Frame-max parameter to ask for (in bytes)</summary>
142+
public uint RequestedFrameMax = DefaultFrameMax;
143+
144+
/// <summary>Heartbeat setting to request (in seconds)</summary>
145+
public ushort RequestedHeartbeat = DefaultHeartbeat;
146+
147+
///<summary>Ssl options setting</summary>
148+
public SslOption Ssl = new SslOption();
149+
150+
///<summary>The host to connect to</summary>
151+
public String HostName = "localhost";
152+
153+
///<summary>The port to connect on. AmqpTcpEndpoint.UseDefaultPort indicates the
154+
/// default for the protocol should be used.</summary>
155+
public int Port = AmqpTcpEndpoint.UseDefaultPort;
156+
157+
///<summary>The AMQP protocol to be used</summary>
158+
public IProtocol Protocol = Protocols.FromEnvironment();
159+
160+
public AmqpTcpEndpoint Endpoint
161+
{
162+
get
163+
{
164+
return new AmqpTcpEndpoint(Protocol, HostName, Port);
165+
}
166+
set
167+
{
168+
Protocol = value.Protocol;
169+
Port = value.Port;
170+
HostName = value.HostName;
171+
}
115172
}
116173

117-
///<summary>Constructs a ConnectionFactory with default values
118-
///for Parameters.</summary>
119-
public ConnectionFactory()
174+
public String Address
120175
{
176+
get
177+
{
178+
String result = HostName;
179+
if(Port != AmqpTcpEndpoint.UseDefaultPort)
180+
{
181+
result += (":" + Port);
182+
}
183+
return result;
184+
}
185+
set
186+
{
187+
Endpoint = AmqpTcpEndpoint.Parse(Protocol, value);
188+
}
121189
}
122190

191+
///<summary>Construct a fresh instance, with all fields set to
192+
///their respective defaults.</summary>
193+
public ConnectionFactory() { }
194+
123195
protected virtual IConnection FollowRedirectChain
124196
(int maxRedirects,
125197
IDictionary connectionAttempts,
@@ -144,7 +216,7 @@ protected virtual IConnection FollowRedirectChain
144216
// and fully open a successful connection,
145217
// in which case we're done, and the
146218
// connection should be returned.
147-
return p.CreateConnection(m_parameters, insist, fh);
219+
return p.CreateConnection(this, insist, fh);
148220
} catch (RedirectException re) {
149221
if (insist) {
150222
// We've been redirected, but we insisted that
@@ -230,79 +302,25 @@ protected virtual IConnection CreateConnection(int maxRedirects,
230302
///endpoint in the list provided. Up to a maximum of
231303
///maxRedirects broker-originated redirects are permitted for
232304
///each endpoint tried.</summary>
233-
public virtual IConnection CreateConnection(int maxRedirects,
234-
params AmqpTcpEndpoint[] endpoints)
305+
public virtual IConnection CreateConnection(int maxRedirects)
235306
{
236307
IDictionary connectionAttempts = new Hashtable();
237308
IDictionary connectionErrors = new Hashtable();
238309
IConnection conn = CreateConnection(maxRedirects,
239310
connectionAttempts,
240311
connectionErrors,
241-
endpoints);
312+
new AmqpTcpEndpoint[]{Endpoint});
242313
if (conn != null) {
243314
return conn;
244315
}
245316
throw new BrokerUnreachableException(connectionAttempts, connectionErrors);
246317
}
247318

248-
///<summary>Create a connection to the first available
249-
///endpoint in the list provided. No broker-originated
250-
///redirects are permitted.</summary>
251-
public virtual IConnection CreateConnection(params AmqpTcpEndpoint[] endpoints)
252-
{
253-
return CreateConnection(0, endpoints);
254-
}
255-
256-
///<summary>Create a connection to the endpoint specified.</summary>
257-
///<exception cref="ArgumentException"/>
258-
public IConnection CreateConnection(IProtocol version,
259-
string hostName,
260-
int portNumber)
261-
{
262-
return CreateConnection(new AmqpTcpEndpoint(version,
263-
hostName,
264-
portNumber,
265-
m_parameters.Ssl));
266-
}
267-
268-
///<summary>Create a connection to the endpoint specified. The
269-
///port used is the default for the protocol.</summary>
270-
///<exception cref="ArgumentException"/>
271-
public IConnection CreateConnection(IProtocol version, string hostName)
319+
///<summary>Create a connection to the specified endpoint
320+
///No broker-originated redirects are permitted.</summary>
321+
public virtual IConnection CreateConnection()
272322
{
273-
return CreateConnection(new AmqpTcpEndpoint(version, hostName));
274-
}
275-
276-
///<summary>Create a connection to the endpoint specified.</summary>
277-
///<remarks>
278-
/// Please see the class overview documentation for
279-
/// information about the Uri format in use.
280-
///</remarks>
281-
///<exception cref="ArgumentException"/>
282-
public IConnection CreateConnection(IProtocol version, Uri uri)
283-
{
284-
return CreateConnection(new AmqpTcpEndpoint(version, uri));
285-
}
286-
287-
///<summary>Create a connection to the endpoint specified,
288-
///with the IProtocol from
289-
///Protocols.FromEnvironment().</summary>
290-
///<remarks>
291-
/// Please see the class overview documentation for
292-
/// information about the Uri format in use.
293-
///</remarks>
294-
public IConnection CreateConnection(Uri uri)
295-
{
296-
return CreateConnection(new AmqpTcpEndpoint(uri));
297-
}
298-
299-
///<summary>Create a connection to the host (and optional
300-
///port) specified, with the IProtocol from
301-
///Protocols.FromEnvironment(). The format of the address
302-
///string is the same as that accepted by
303-
///AmqpTcpEndpoint.Parse().</summary>
304-
public IConnection CreateConnection(string address) {
305-
return CreateConnection(AmqpTcpEndpoint.Parse(Protocols.FromEnvironment(), address));
323+
return CreateConnection(0);
306324
}
307325
}
308326
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ public interface IConnection: IDisposable
103103
///communicate with its peer.</summary>
104104
IProtocol Protocol { get; }
105105

106-
///<summary>The connection parameters used during construction
107-
///of this connection.</summary>
108-
ConnectionParameters Parameters { get; }
109-
110106
///<summary>The maximum channel number this connection
111107
///supports (0 if unlimited). Usable channel numbers
112108
///range from 1 to this number, inclusive.</summary>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public interface IProtocol
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>
81-
IConnection CreateConnection(ConnectionParameters parameters,
81+
IConnection CreateConnection(ConnectionFactory factory,
8282
bool insist,
8383
IFrameHandler frameHandler);
8484
///<summary>Construct a protocol model atop a given session.</summary>

projects/client/RabbitMQ.Client/src/client/impl/AbstractProtocolBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public abstract class AbstractProtocolBase: IProtocol {
6666
public abstract int DefaultPort { get; }
6767

6868
public abstract IFrameHandler CreateFrameHandler(AmqpTcpEndpoint endpoint);
69-
public abstract IConnection CreateConnection(ConnectionParameters parameters,
69+
public abstract IConnection CreateConnection(ConnectionFactory factory,
7070
bool insist,
7171
IFrameHandler frameHandler);
7272
public abstract IModel CreateModel(ISession session);

projects/client/RabbitMQ.Client/src/client/impl/ConnectionBase.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public abstract class ConnectionBase : IConnection
8989
///(milliseconds)</summary>
9090
public static int ConnectionCloseTimeout = 10000;
9191

92-
public ConnectionParameters m_parameters;
92+
public ConnectionFactory m_factory;
9393
public IFrameHandler m_frameHandler;
9494
public uint m_frameMax = 0;
9595
public ushort m_heartbeat = 0;
@@ -119,11 +119,11 @@ public abstract class ConnectionBase : IConnection
119119

120120
public IList m_shutdownReport = ArrayList.Synchronized(new ArrayList());
121121

122-
public ConnectionBase(ConnectionParameters parameters,
122+
public ConnectionBase(ConnectionFactory factory,
123123
bool insist,
124124
IFrameHandler frameHandler)
125125
{
126-
m_parameters = parameters;
126+
m_factory = factory;
127127
m_frameHandler = frameHandler;
128128

129129
m_sessionManager = new SessionManager(this, 0);
@@ -214,14 +214,6 @@ public void WriteFrame(Frame f)
214214
m_heartbeatWrite.Set();
215215
}
216216

217-
public ConnectionParameters Parameters
218-
{
219-
get
220-
{
221-
return m_parameters;
222-
}
223-
}
224-
225217
public ushort ChannelMax
226218
{
227219
get
@@ -966,27 +958,27 @@ public void Open(bool insist)
966958
ConnectionTuneDetails connectionTune =
967959
m_model0.ConnectionStartOk(BuildClientPropertiesTable(),
968960
"PLAIN",
969-
Encoding.UTF8.GetBytes("\0" + m_parameters.UserName +
970-
"\0" + m_parameters.Password),
961+
Encoding.UTF8.GetBytes("\0" + m_factory.UserName +
962+
"\0" + m_factory.Password),
971963
"en_US");
972964

973-
ushort channelMax = (ushort) NegotiatedMaxValue(m_parameters.RequestedChannelMax,
965+
ushort channelMax = (ushort) NegotiatedMaxValue(m_factory.RequestedChannelMax,
974966
connectionTune.m_channelMax);
975967
m_sessionManager = new SessionManager(this, channelMax);
976968

977-
uint frameMax = NegotiatedMaxValue(m_parameters.RequestedFrameMax,
969+
uint frameMax = NegotiatedMaxValue(m_factory.RequestedFrameMax,
978970
connectionTune.m_frameMax);
979971
FrameMax = frameMax;
980972

981-
ushort heartbeat = (ushort) NegotiatedMaxValue(m_parameters.RequestedHeartbeat,
973+
ushort heartbeat = (ushort) NegotiatedMaxValue(m_factory.RequestedHeartbeat,
982974
connectionTune.m_heartbeat);
983975
Heartbeat = heartbeat;
984976

985977
m_model0.ConnectionTuneOk(channelMax,
986978
frameMax,
987979
heartbeat);
988980

989-
string knownHosts = m_model0.ConnectionOpen(m_parameters.VirtualHost,
981+
string knownHosts = m_model0.ConnectionOpen(m_factory.VirtualHost,
990982
"", // FIXME: make configurable?
991983
insist);
992984
KnownHosts = AmqpTcpEndpoint.ParseMultiple(Protocol, knownHosts);

projects/client/RabbitMQ.Client/src/client/impl/v0_8/Connection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
namespace RabbitMQ.Client.Framing.Impl.v0_8 {
6161
public class Connection: ConnectionBase {
62-
public Connection(ConnectionParameters parameters, bool insist, IFrameHandler frameHandler)
63-
: base(parameters, insist, frameHandler) {}
62+
public Connection(ConnectionFactory factory, bool insist, IFrameHandler frameHandler)
63+
: base(factory, insist, frameHandler) {}
6464
}
6565
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ public override IModel CreateModel(ISession session) {
6969
return new Model(session);
7070
}
7171

72-
public override IConnection CreateConnection(ConnectionParameters parameters,
72+
public override IConnection CreateConnection(ConnectionFactory factory,
7373
bool insist,
7474
IFrameHandler frameHandler)
7575
{
76-
return new Connection(parameters, insist, frameHandler);
76+
return new Connection(factory, insist, frameHandler);
7777
}
7878

7979
public override void CreateConnectionClose(ushort reasonCode,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
namespace RabbitMQ.Client.Framing.Impl.v0_8qpid {
6161
public class Connection: ConnectionBase {
62-
public Connection(ConnectionParameters parameters, bool insist, IFrameHandler frameHandler)
63-
: base(parameters, insist, frameHandler) {}
62+
public Connection(ConnectionFactory factory , bool insist, IFrameHandler frameHandler)
63+
: base(factory, insist, frameHandler) {}
6464
}
6565
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ public override IModel CreateModel(ISession session) {
6969
return new Model(session);
7070
}
7171

72-
public override IConnection CreateConnection(ConnectionParameters parameters,
72+
public override IConnection CreateConnection(ConnectionFactory factory,
7373
bool insist,
7474
IFrameHandler frameHandler)
7575
{
76-
return new Connection(parameters, insist, frameHandler);
76+
return new Connection(factory, insist, frameHandler);
7777
}
7878

7979
public override void CreateConnectionClose(ushort reasonCode,

0 commit comments

Comments
 (0)