Skip to content

Commit 58eb2d1

Browse files
author
David R. MacIver
committed
unrevert reversion. Sigh
1 parent a2ad6a2 commit 58eb2d1

File tree

15 files changed

+77
-204
lines changed

15 files changed

+77
-204
lines changed

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

Lines changed: 26 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ namespace RabbitMQ.Client
7575
/// ConnectionFactory factory = new ConnectionFactory();
7676
/// //
7777
/// // The next three lines are optional:
78-
/// factory.Parameters.UserName = ConnectionParameters.DefaultUser;
79-
/// factory.Parameters.Password = ConnectionParameters.DefaultPass;
80-
/// factory.Parameters.VirtualHost = ConnectionParameters.DefaultVHost;
78+
/// factory.Parameters.UserName = AMQPParameters.DefaultUser;
79+
/// factory.Parameters.Password = AMQPParameters.DefaultPass;
80+
/// factory.Parameters.VirtualHost = AMQPParameters.DefaultVHost;
8181
/// //
8282
/// IProtocol protocol = Protocols.DefaultProtocol;
8383
/// IConnection conn = factory.CreateConnection(protocol, hostName, portNumber);
@@ -103,17 +103,8 @@ namespace RabbitMQ.Client
103103
///</remarks>
104104
public class ConnectionFactory
105105
{
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-
}
115-
}
116-
106+
public ConnectionParameters[] ConnectionParameters = { new ConnectionParameters() };
107+
117108
///<summary>Constructs a ConnectionFactory with default values
118109
///for Parameters.</summary>
119110
public ConnectionFactory()
@@ -124,10 +115,10 @@ protected virtual IConnection FollowRedirectChain
124115
(int maxRedirects,
125116
IDictionary connectionAttempts,
126117
IDictionary connectionErrors,
127-
ref AmqpTcpEndpoint[] mostRecentKnownHosts,
128-
AmqpTcpEndpoint endpoint)
118+
ref ConnectionParameters[] mostRecentKnownHosts,
119+
ConnectionParameters endpoint)
129120
{
130-
AmqpTcpEndpoint candidate = endpoint;
121+
ConnectionParameters candidate = endpoint;
131122
try {
132123
while (true) {
133124
int attemptCount =
@@ -138,13 +129,13 @@ protected virtual IConnection FollowRedirectChain
138129
bool insist = attemptCount >= maxRedirects;
139130

140131
try {
141-
IProtocol p = candidate.Protocol;
142-
IFrameHandler fh = p.CreateFrameHandler(candidate);
132+
IProtocol p = candidate.AMQP.Protocol;
133+
IFrameHandler fh = p.CreateFrameHandler(candidate.TCP);
143134
// At this point, we may be able to create
144135
// and fully open a successful connection,
145136
// in which case we're done, and the
146137
// connection should be returned.
147-
return p.CreateConnection(m_parameters, insist, fh);
138+
return p.CreateConnection(candidate.AMQP, insist, fh);
148139
} catch (RedirectException re) {
149140
if (insist) {
150141
// We've been redirected, but we insisted that
@@ -160,9 +151,12 @@ protected virtual IConnection FollowRedirectChain
160151
// mostRecentKnownHosts (in case the chain
161152
// runs out), and updating candidate for the
162153
// next time round the loop.
163-
connectionErrors[candidate] = re;
164-
mostRecentKnownHosts = re.KnownHosts;
165-
candidate = re.Host;
154+
connectionErrors[candidate] = re;
155+
mostRecentKnownHosts = new ConnectionParameters[re.KnownHosts.Length];
156+
for(int i = 0; i < re.KnownHosts.Length; i++){
157+
mostRecentKnownHosts[i] = new ConnectionParameters(candidate.AMQP, re.KnownHosts[i]);
158+
}
159+
candidate = new ConnectionParameters(candidate.AMQP, re.Host);
166160
}
167161
}
168162
}
@@ -175,13 +169,14 @@ protected virtual IConnection FollowRedirectChain
175169
protected virtual IConnection CreateConnection(int maxRedirects,
176170
IDictionary connectionAttempts,
177171
IDictionary connectionErrors,
178-
params AmqpTcpEndpoint[] endpoints)
172+
ConnectionParameters[] endpoints)
179173
{
180-
foreach (AmqpTcpEndpoint endpoint in endpoints)
174+
foreach (ConnectionParameters endpoint in endpoints)
181175
{
182-
AmqpTcpEndpoint[] mostRecentKnownHosts = new AmqpTcpEndpoint[0];
176+
ConnectionParameters[] mostRecentKnownHosts = new ConnectionParameters[0];
183177
// ^^ holds a list of known-hosts that came back with
184-
// a connection.redirect. If, once we reach the end of
178+
// a connection.redirect, together with the AMQPParameters
179+
// used for that connection attempt. If, once we reach the end of
185180
// a chain of redirects, we still haven't managed to
186181
// get a usable connection, we recurse on
187182
// mostRecentKnownHosts, trying each of those in
@@ -230,15 +225,14 @@ protected virtual IConnection CreateConnection(int maxRedirects,
230225
///endpoint in the list provided. Up to a maximum of
231226
///maxRedirects broker-originated redirects are permitted for
232227
///each endpoint tried.</summary>
233-
public virtual IConnection CreateConnection(int maxRedirects,
234-
params AmqpTcpEndpoint[] endpoints)
228+
public virtual IConnection CreateConnection(int maxRedirects)
235229
{
236230
IDictionary connectionAttempts = new Hashtable();
237231
IDictionary connectionErrors = new Hashtable();
238232
IConnection conn = CreateConnection(maxRedirects,
239233
connectionAttempts,
240234
connectionErrors,
241-
endpoints);
235+
ConnectionParameters);
242236
if (conn != null) {
243237
return conn;
244238
}
@@ -248,61 +242,9 @@ public virtual IConnection CreateConnection(int maxRedirects,
248242
///<summary>Create a connection to the first available
249243
///endpoint in the list provided. No broker-originated
250244
///redirects are permitted.</summary>
251-
public virtual IConnection CreateConnection(params AmqpTcpEndpoint[] endpoints)
245+
public virtual IConnection CreateConnection()
252246
{
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)
272-
{
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));
247+
return CreateConnection(0);
306248
}
307249
}
308250
}

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

Lines changed: 20 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -60,101 +60,32 @@ namespace RabbitMQ.Client
6060
{
6161
///<summary>Supplies values to ConnectionFactory for use in
6262
///constructing IConnection instances.</summary>
63-
public class ConnectionParameters : ICloneable
63+
public class ConnectionParameters
6464
{
65-
/// <summary>Default user name (value: "guest")</summary>
66-
public const string DefaultUser = "guest"; // PLEASE KEEP THIS MATCHING THE DOC ABOVE
65+
public AMQPParameters AMQP;
66+
public AmqpTcpEndpoint TCP;
6767

68-
/// <summary>Default password (value: "guest")</summary>
69-
public const string DefaultPass = "guest"; // PLEASE KEEP THIS MATCHING THE DOC ABOVE
68+
public ConnectionParameters(AMQPParameters amqp, AmqpTcpEndpoint tcp){
69+
AMQP = amqp;
70+
TCP = tcp;
71+
}
7072

71-
/// <summary>Default virtual host (value: "/")</summary>
72-
public const string DefaultVHost = "/"; // PLEASE KEEP THIS MATCHING THE DOC ABOVE
73+
public ConnectionParameters() : this(new AMQPParameters(), new AmqpTcpEndpoint()){
74+
}
7375

74-
/// <summary> Default value for the desired maximum channel
75-
/// number, with zero meaning unlimited (value: 0)</summary>
76-
public const ushort DefaultChannelMax = 0; // PLEASE KEEP THIS MATCHING THE DOC ABOVE
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;
7779

78-
/// <summary>Default value for the desired maximum frame size,
79-
/// with zero meaning unlimited (value: 0)</summary>
80-
public const uint DefaultFrameMax = 0; // PLEASE KEEP THIS MATCHING THE DOC ABOVE
8180

82-
/// <summary>Default value for desired heartbeat interval, in
83-
/// seconds, with zero meaning none (value: 0)</summary>
84-
public const ushort DefaultHeartbeat = 0; // PLEASE KEEP THIS MATCHING THE DOC ABOVE
85-
86-
private string m_userName = DefaultUser;
87-
private string m_password = DefaultPass;
88-
private string m_virtualHost = DefaultVHost;
89-
private ushort m_requestedChannelMax = DefaultChannelMax;
90-
private uint m_requestedFrameMax = DefaultFrameMax;
91-
private ushort m_requestedHeartbeat = DefaultHeartbeat;
92-
private SslOption m_ssl = new SslOption();
93-
94-
///<summary>Construct a fresh instance, with all fields set to
95-
///their respective defaults.</summary>
96-
public ConnectionParameters() { }
97-
98-
/// <summary>Username to use when authenticating to the server</summary>
99-
public string UserName
100-
{
101-
get { return m_userName; }
102-
set { m_userName = value; }
103-
}
104-
105-
/// <summary>Password to use when authenticating to the server</summary>
106-
public string Password
107-
{
108-
get { return m_password; }
109-
set { m_password = value; }
110-
}
111-
112-
/// <summary>Virtual host to access during this connection</summary>
113-
public string VirtualHost
114-
{
115-
get { return m_virtualHost; }
116-
set { m_virtualHost = value; }
117-
}
118-
119-
/// <summary>Maximum channel number to ask for</summary>
120-
public ushort RequestedChannelMax
121-
{
122-
get { return m_requestedChannelMax; }
123-
set { m_requestedChannelMax = value; }
124-
}
125-
126-
/// <summary>Frame-max parameter to ask for (in bytes)</summary>
127-
public uint RequestedFrameMax
128-
{
129-
get { return m_requestedFrameMax; }
130-
set { m_requestedFrameMax = value; }
131-
}
132-
133-
/// <summary>Heartbeat setting to request (in seconds)</summary>
134-
public ushort RequestedHeartbeat
135-
{
136-
get { return m_requestedHeartbeat; }
137-
set { m_requestedHeartbeat = value; }
138-
}
139-
140-
///<summary>Ssl options setting</summary>
141-
public SslOption Ssl
142-
{
143-
get { return m_ssl; }
144-
set { m_ssl = value; }
145-
}
146-
147-
///<summary>Implement ICloneable.Clone by delegating to our type-safe variant.</summary>
148-
object ICloneable.Clone()
149-
{
150-
return ((ConnectionParameters)this).Clone();
151-
}
152-
153-
///<summary>Returns a fresh ConnectionParameters with the same values as this.</summary>
154-
public ConnectionParameters Clone()
155-
{
156-
ConnectionParameters n = this.MemberwiseClone() as ConnectionParameters;
157-
return n;
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+
}
15888
}
89+
}
15990
}
16091
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public interface IConnection: IDisposable
105105

106106
///<summary>The connection parameters used during construction
107107
///of this connection.</summary>
108-
ConnectionParameters Parameters { get; }
108+
AMQPParameters Parameters { get; }
109109

110110
///<summary>The maximum channel number this connection
111111
///supports (0 if unlimited). Usable channel numbers

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(AMQPParameters parameters,
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(AMQPParameters parameters,
7070
bool insist,
7171
IFrameHandler frameHandler);
7272
public abstract IModel CreateModel(ISession session);

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

Lines changed: 3 additions & 3 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 AMQPParameters m_parameters;
9393
public IFrameHandler m_frameHandler;
9494
public uint m_frameMax = 0;
9595
public ushort m_heartbeat = 0;
@@ -119,7 +119,7 @@ public abstract class ConnectionBase : IConnection
119119

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

122-
public ConnectionBase(ConnectionParameters parameters,
122+
public ConnectionBase(AMQPParameters parameters,
123123
bool insist,
124124
IFrameHandler frameHandler)
125125
{
@@ -214,7 +214,7 @@ public void WriteFrame(Frame f)
214214
m_heartbeatWrite.Set();
215215
}
216216

217-
public ConnectionParameters Parameters
217+
public AMQPParameters Parameters
218218
{
219219
get
220220
{

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

Lines changed: 1 addition & 1 deletion
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)
62+
public Connection(AMQPParameters parameters, bool insist, IFrameHandler frameHandler)
6363
: base(parameters, insist, frameHandler) {}
6464
}
6565
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ 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(AMQPParameters parameters,
7373
bool insist,
7474
IFrameHandler frameHandler)
7575
{

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

Lines changed: 1 addition & 1 deletion
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)
62+
public Connection(AMQPParameters parameters, bool insist, IFrameHandler frameHandler)
6363
: base(parameters, insist, frameHandler) {}
6464
}
6565
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ 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(AMQPParameters parameters,
7373
bool insist,
7474
IFrameHandler frameHandler)
7575
{

0 commit comments

Comments
 (0)