Skip to content

Commit b845632

Browse files
author
David R. MacIver
committed
Client is now compiling with new parameter layout. Tests don't yet compile. Will need to do some refactoring to fix code for using URLs.
1 parent f595de0 commit b845632

File tree

3 files changed

+130
-81
lines changed

3 files changed

+130
-81
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,27 @@ public class AMQPParameters : ICloneable
9090
private uint m_requestedFrameMax = DefaultFrameMax;
9191
private ushort m_requestedHeartbeat = DefaultHeartbeat;
9292
private SslOption m_ssl = new SslOption();
93+
private IProtocol m_protocol;
9394

9495
///<summary>Construct a fresh instance, with all fields set to
9596
///their respective defaults.</summary>
9697
public AMQPParameters() { }
9798

99+
///<summary>Retrieve or set the IProtocol of this AmqpTcpEndpoint.</summary>
100+
public IProtocol Protocol
101+
{
102+
get { return m_protocol; }
103+
set { m_protocol = value; }
104+
}
105+
106+
private string m_hostName;
107+
///<summary>Retrieve or set the hostname of this AmqpTcpEndpoint.</summary>
108+
public string HostName
109+
{
110+
get { return m_hostName; }
111+
set { m_hostName = value; }
112+
}
113+
98114
/// <summary>Username to use when authenticating to the server</summary>
99115
public string UserName
100116
{

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

Lines changed: 23 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,8 @@ namespace RabbitMQ.Client
103103
///</remarks>
104104
public class ConnectionFactory
105105
{
106-
private AMQPParameters m_parameters = new AMQPParameters();
107-
///<summary>Retrieve the parameters this factory uses to
108-
///construct IConnection instances.</summary>
109-
public AMQPParameters 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
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 1.1.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (C) 2007-2009 LShift Ltd., Cohesive Financial
8+
// Technologies LLC., and Rabbit Technologies Ltd.
9+
//
10+
// Licensed under the Apache License, Version 2.0 (the "License");
11+
// you may not use this file except in compliance with the License.
12+
// You may obtain a copy of the License at
13+
//
14+
// http://www.apache.org/licenses/LICENSE-2.0
15+
//
16+
// Unless required by applicable law or agreed to in writing, software
17+
// distributed under the License is distributed on an "AS IS" BASIS,
18+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
// See the License for the specific language governing permissions and
20+
// limitations under the License.
21+
//---------------------------------------------------------------------------
22+
//
23+
// The MPL v1.1:
24+
//
25+
//---------------------------------------------------------------------------
26+
// The contents of this file are subject to the Mozilla Public License
27+
// Version 1.1 (the "License"); you may not use this file except in
28+
// compliance with the License. You may obtain a copy of the License at
29+
// http://www.rabbitmq.com/mpl.html
30+
//
31+
// Software distributed under the License is distributed on an "AS IS"
32+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
33+
// License for the specific language governing rights and limitations
34+
// under the License.
35+
//
36+
// The Original Code is The RabbitMQ .NET Client.
37+
//
38+
// The Initial Developers of the Original Code are LShift Ltd,
39+
// Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
40+
//
41+
// Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
42+
// Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
43+
// are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
44+
// Technologies LLC, and Rabbit Technologies Ltd.
45+
//
46+
// Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
47+
// Ltd. Portions created by Cohesive Financial Technologies LLC are
48+
// Copyright (C) 2007-2009 Cohesive Financial Technologies
49+
// LLC. Portions created by Rabbit Technologies Ltd are Copyright
50+
// (C) 2007-2009 Rabbit Technologies Ltd.
51+
//
52+
// All Rights Reserved.
53+
//
54+
// Contributor(s): ______________________________________.
55+
//
56+
//---------------------------------------------------------------------------
57+
using System;
58+
59+
namespace RabbitMQ.Client
60+
{
61+
///<summary>Supplies values to ConnectionFactory for use in
62+
///constructing IConnection instances.</summary>
63+
public class ConnectionParameters
64+
{
65+
public AMQPParameters AMQP;
66+
public AmqpTcpEndpoint TCP;
67+
68+
public ConnectionParameters(AMQPParameters amqp, AmqpTcpEndpoint tcp){
69+
AMQP = amqp;
70+
TCP = tcp;
71+
}
72+
73+
public ConnectionParameters() : this(new AMQPParameters(), new AmqpTcpEndpoint()){
74+
}
75+
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+
}
90+
}
91+
}

0 commit comments

Comments
 (0)