@@ -74,13 +74,15 @@ namespace RabbitMQ.Client
74
74
///<example><code>
75
75
/// ConnectionFactory factory = new ConnectionFactory();
76
76
/// //
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;
81
84
/// //
82
- /// IProtocol protocol = Protocols.DefaultProtocol;
83
- /// IConnection conn = factory.CreateConnection(protocol, hostName, portNumber);
85
+ /// IConnection conn = factory.CreateConnection();
84
86
/// //
85
87
/// IModel ch = conn.CreateModel();
86
88
/// //
@@ -103,23 +105,93 @@ namespace RabbitMQ.Client
103
105
///</remarks>
104
106
public class ConnectionFactory
105
107
{
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
+ }
115
172
}
116
173
117
- ///<summary>Constructs a ConnectionFactory with default values
118
- ///for Parameters.</summary>
119
- public ConnectionFactory ( )
174
+ public String Address
120
175
{
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
+ }
121
189
}
122
190
191
+ ///<summary>Construct a fresh instance, with all fields set to
192
+ ///their respective defaults.</summary>
193
+ public ConnectionFactory ( ) { }
194
+
123
195
protected virtual IConnection FollowRedirectChain
124
196
( int maxRedirects ,
125
197
IDictionary connectionAttempts ,
@@ -144,7 +216,7 @@ protected virtual IConnection FollowRedirectChain
144
216
// and fully open a successful connection,
145
217
// in which case we're done, and the
146
218
// connection should be returned.
147
- return p . CreateConnection ( m_parameters , insist , fh ) ;
219
+ return p . CreateConnection ( this , insist , fh ) ;
148
220
} catch ( RedirectException re ) {
149
221
if ( insist ) {
150
222
// We've been redirected, but we insisted that
@@ -230,79 +302,25 @@ protected virtual IConnection CreateConnection(int maxRedirects,
230
302
///endpoint in the list provided. Up to a maximum of
231
303
///maxRedirects broker-originated redirects are permitted for
232
304
///each endpoint tried.</summary>
233
- public virtual IConnection CreateConnection ( int maxRedirects ,
234
- params AmqpTcpEndpoint [ ] endpoints )
305
+ public virtual IConnection CreateConnection ( int maxRedirects )
235
306
{
236
307
IDictionary connectionAttempts = new Hashtable ( ) ;
237
308
IDictionary connectionErrors = new Hashtable ( ) ;
238
309
IConnection conn = CreateConnection ( maxRedirects ,
239
310
connectionAttempts ,
240
311
connectionErrors ,
241
- endpoints ) ;
312
+ new AmqpTcpEndpoint [ ] { Endpoint } ) ;
242
313
if ( conn != null ) {
243
314
return conn ;
244
315
}
245
316
throw new BrokerUnreachableException ( connectionAttempts , connectionErrors ) ;
246
317
}
247
318
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 ( )
272
322
{
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 ) ;
306
324
}
307
325
}
308
326
}
0 commit comments