@@ -103,8 +103,17 @@ namespace RabbitMQ.Client
103
103
///</remarks>
104
104
public class ConnectionFactory
105
105
{
106
- public ConnectionParameters [ ] ConnectionParameters = { new ConnectionParameters ( ) } ;
107
-
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
+
108
117
///<summary>Constructs a ConnectionFactory with default values
109
118
///for Parameters.</summary>
110
119
public ConnectionFactory ( )
@@ -115,10 +124,10 @@ protected virtual IConnection FollowRedirectChain
115
124
( int maxRedirects ,
116
125
IDictionary connectionAttempts ,
117
126
IDictionary connectionErrors ,
118
- ref ConnectionParameters [ ] mostRecentKnownHosts ,
119
- ConnectionParameters endpoint )
127
+ ref AmqpTcpEndpoint [ ] mostRecentKnownHosts ,
128
+ AmqpTcpEndpoint endpoint )
120
129
{
121
- ConnectionParameters candidate = endpoint ;
130
+ AmqpTcpEndpoint candidate = endpoint ;
122
131
try {
123
132
while ( true ) {
124
133
int attemptCount =
@@ -129,13 +138,13 @@ protected virtual IConnection FollowRedirectChain
129
138
bool insist = attemptCount >= maxRedirects ;
130
139
131
140
try {
132
- IProtocol p = candidate . AMQP . Protocol ;
133
- IFrameHandler fh = p . CreateFrameHandler ( candidate . TCP ) ;
141
+ IProtocol p = candidate . Protocol ;
142
+ IFrameHandler fh = p . CreateFrameHandler ( candidate ) ;
134
143
// At this point, we may be able to create
135
144
// and fully open a successful connection,
136
145
// in which case we're done, and the
137
146
// connection should be returned.
138
- return p . CreateConnection ( candidate . AMQP , insist , fh ) ;
147
+ return p . CreateConnection ( m_parameters , insist , fh ) ;
139
148
} catch ( RedirectException re ) {
140
149
if ( insist ) {
141
150
// We've been redirected, but we insisted that
@@ -151,12 +160,9 @@ protected virtual IConnection FollowRedirectChain
151
160
// mostRecentKnownHosts (in case the chain
152
161
// runs out), and updating candidate for the
153
162
// next time round the loop.
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 ) ;
163
+ connectionErrors [ candidate ] = re ;
164
+ mostRecentKnownHosts = re . KnownHosts ;
165
+ candidate = re . Host ;
160
166
}
161
167
}
162
168
}
@@ -169,14 +175,13 @@ protected virtual IConnection FollowRedirectChain
169
175
protected virtual IConnection CreateConnection ( int maxRedirects ,
170
176
IDictionary connectionAttempts ,
171
177
IDictionary connectionErrors ,
172
- ConnectionParameters [ ] endpoints )
178
+ params AmqpTcpEndpoint [ ] endpoints )
173
179
{
174
- foreach ( ConnectionParameters endpoint in endpoints )
180
+ foreach ( AmqpTcpEndpoint endpoint in endpoints )
175
181
{
176
- ConnectionParameters [ ] mostRecentKnownHosts = new ConnectionParameters [ 0 ] ;
182
+ AmqpTcpEndpoint [ ] mostRecentKnownHosts = new AmqpTcpEndpoint [ 0 ] ;
177
183
// ^^ holds a list of known-hosts that came back with
178
- // a connection.redirect, together with the AMQPParameters
179
- // used for that connection attempt. If, once we reach the end of
184
+ // a connection.redirect. If, once we reach the end of
180
185
// a chain of redirects, we still haven't managed to
181
186
// get a usable connection, we recurse on
182
187
// mostRecentKnownHosts, trying each of those in
@@ -225,14 +230,15 @@ protected virtual IConnection CreateConnection(int maxRedirects,
225
230
///endpoint in the list provided. Up to a maximum of
226
231
///maxRedirects broker-originated redirects are permitted for
227
232
///each endpoint tried.</summary>
228
- public virtual IConnection CreateConnection ( int maxRedirects )
233
+ public virtual IConnection CreateConnection ( int maxRedirects ,
234
+ params AmqpTcpEndpoint [ ] endpoints )
229
235
{
230
236
IDictionary connectionAttempts = new Hashtable ( ) ;
231
237
IDictionary connectionErrors = new Hashtable ( ) ;
232
238
IConnection conn = CreateConnection ( maxRedirects ,
233
239
connectionAttempts ,
234
240
connectionErrors ,
235
- ConnectionParameters ) ;
241
+ endpoints ) ;
236
242
if ( conn != null ) {
237
243
return conn ;
238
244
}
@@ -242,9 +248,61 @@ public virtual IConnection CreateConnection(int maxRedirects)
242
248
///<summary>Create a connection to the first available
243
249
///endpoint in the list provided. No broker-originated
244
250
///redirects are permitted.</summary>
245
- public virtual IConnection CreateConnection ( )
251
+ public virtual IConnection CreateConnection ( params AmqpTcpEndpoint [ ] endpoints )
246
252
{
247
- return CreateConnection ( 0 ) ;
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 ) ) ;
248
306
}
249
307
}
250
308
}
0 commit comments