@@ -77,11 +77,6 @@ namespace RabbitMQ.Client.MessagePatterns {
77
77
/// IEnumerator in, for example, a foreach loop.
78
78
///</para>
79
79
///<para>
80
- /// See the documentation for Bind() and for the various overloads
81
- /// of the constructor for the various styles of binding and
82
- /// subscription that are available.
83
- ///</para>
84
- ///<para>
85
80
/// Note that if the "noAck" option is enabled (which it is by
86
81
/// default), then received deliveries are automatically acked
87
82
/// within the server before they are even transmitted across the
@@ -103,11 +98,8 @@ public class Subscription: IEnumerable, IEnumerator, IDisposable {
103
98
protected readonly object m_consumerLock = new object ( ) ;
104
99
protected volatile QueueingBasicConsumer m_consumer ;
105
100
protected string m_consumerTag ;
106
- protected volatile bool m_shouldDelete ;
107
101
108
- ///<summary>Retrieve the queue name we have subscribed to. May
109
- ///be a server-generated name, depending on how the
110
- ///Subscription was constructed.</summary>
102
+ ///<summary>Retrieve the queue name we have subscribed to.</summary>
111
103
public string QueueName { get { return m_queueName ; } }
112
104
///<summary>Retrieve the IBasicConsumer that is receiving the
113
105
///messages from the server for us. Normally, you will not
@@ -136,147 +128,44 @@ public class Subscription: IEnumerable, IEnumerator, IDisposable {
136
128
public BasicDeliverEventArgs LatestEvent { get { return m_latestEvent ; } }
137
129
138
130
///<summary>Creates a new Subscription in "noAck" mode,
139
- ///consuming from a fresh, exclusive, autodelete, anonymous
140
- ///queue. The name of the queue can be retrieved using the
141
- ///QueueName property of the Subscription. After creating the
142
- ///queue, the queue is bound to the named exchange, using
143
- ///Bind() with the given routingKey bind parameter.</summary>
144
- public Subscription ( IModel model , string exchangeName ,
145
- string exchangeType , string routingKey )
146
- : this ( model )
147
- {
148
- Bind ( exchangeName , exchangeType , routingKey ) ;
149
- }
150
-
151
- ///<summary>Creates a new Subscription in "noAck" mode,
152
- ///consuming from a fresh, exclusive, autodelete, anonymous
153
- ///queue. The name of the queue can be retrieved using the
154
- ///QueueName property of the Subscription.</summary>
155
- public Subscription ( IModel model )
156
- : this ( model , null ) { }
157
-
158
- ///<summary>Creates a new Subscription in "noAck" mode,
159
- ///consuming from a named queue. If the queueName parameter is
160
- ///null or the empty-string, creates a fresh, exclusive,
161
- ///autodelete, anonymous queue; otherwise, the queue is
162
- ///declared using IModel.QueueDeclare() before
163
- ///IModel.BasicConsume() is called. After declaring the queue
164
- ///and starting the consumer, the queue is bound to the named
165
- ///exchange, using Bind() with the given routingKey bind
166
- ///parameter.</summary>
167
- public Subscription ( IModel model , string queueName , string exchangeName ,
168
- string exchangeType , string routingKey )
169
- : this ( model , queueName )
170
- {
171
- Bind ( exchangeName , exchangeType , routingKey ) ;
172
- }
173
-
174
- ///<summary>Creates a new Subscription in "noAck" mode,
175
- ///consuming from a named queue. If the queueName parameter is
176
- ///null or the empty-string, creates a fresh, exclusive,
177
- ///autodelete, anonymous queue; otherwise, the queue is
178
- ///declared using IModel.QueueDeclare() before
179
- ///IModel.BasicConsume() is called.</summary>
131
+ ///consuming from a named queue.</summary>
180
132
public Subscription ( IModel model , string queueName )
181
133
: this ( model , queueName , true ) { }
182
134
183
135
///<summary>Creates a new Subscription, with full control over
184
- ///both "noAck" mode and the name of the queue (which, if null
185
- ///or the empty-string, will be a fresh, exclusive,
186
- ///autodelete, anonymous queue, as for the other constructor
187
- ///overloads). After declaring the queue and starting the
188
- ///consumer, the queue is bound to the named exchange, using
189
- ///Bind() with the given routingKey bind parameter.</summary>
190
- public Subscription ( IModel model , string queueName , bool noAck ,
191
- string exchangeName , string exchangeType , string routingKey )
192
- : this ( model , queueName , noAck )
193
- {
194
- Bind ( exchangeName , exchangeType , routingKey ) ;
195
- }
196
-
197
- ///<summary>Creates a new Subscription, with full control over
198
- ///both "noAck" mode and the name of the queue (which, if null
199
- ///or the empty-string, will be a fresh, exclusive,
200
- ///autodelete, anonymous queue, as for the other constructor
201
- ///overloads).</summary>
136
+ ///both "noAck" mode and the name of the queue.</summary>
202
137
public Subscription ( IModel model , string queueName , bool noAck )
203
138
{
204
139
m_model = model ;
205
- if ( queueName == null || queueName . Equals ( "" ) ) {
206
- m_queueName = m_model . QueueDeclare ( ) ;
207
- m_shouldDelete = true ;
208
- } else {
209
- m_queueName = m_model . QueueDeclare ( queueName ) ;
210
- m_shouldDelete = false ;
211
- }
140
+ m_queueName = queueName ;
212
141
m_consumer = new QueueingBasicConsumer ( m_model ) ;
213
142
m_consumerTag = m_model . BasicConsume ( m_queueName , m_noAck , null , m_consumer ) ;
214
143
m_latestEvent = null ;
215
144
}
216
145
217
146
///<summary>Closes this Subscription, cancelling the consumer
218
- ///record in the server. If an anonymous, exclusive,
219
- ///autodelete queue (i.e., one with a server-generated name)
220
- ///was created during construction of the Subscription, this
221
- ///method also deletes the created queue (which is an
222
- ///optimisation: autodelete queues will be deleted when the
223
- ///IModel closes in any case).</summary>
147
+ ///record in the server.</summary>
224
148
public void Close ( )
225
149
{
226
150
try {
227
151
bool shouldCancelConsumer = false ;
228
- bool shouldDelete = false ;
229
152
230
153
lock ( m_consumerLock ) {
231
154
if ( m_consumer != null ) {
232
155
shouldCancelConsumer = true ;
233
156
m_consumer = null ;
234
157
}
235
-
236
- shouldDelete = m_shouldDelete ;
237
- // We set m_shouldDelete false before attempting
238
- // the delete, because trying twice is worse than
239
- // trying once and failing.
240
- m_shouldDelete = false ;
241
158
}
242
159
243
160
if ( shouldCancelConsumer ) {
244
161
m_model . BasicCancel ( m_consumerTag ) ;
245
162
m_consumerTag = null ;
246
163
}
247
-
248
- if ( shouldDelete ) {
249
- m_model . QueueDelete ( m_queueName , false , false , false ) ;
250
- }
251
164
} catch ( OperationInterruptedException ) {
252
165
// We don't mind, here.
253
166
}
254
167
}
255
168
256
- ///<summary>Causes the queue to which we have subscribed to be
257
- ///bound to an exchange. Uses IModel.ExchangeDeclare and
258
- ///IModel.QueueBind to (a) ensure the exchange exists, and (b)
259
- ///link the exchange to our queue.</summary>
260
- ///<remarks>
261
- ///<para>
262
- /// This method is called by some of the overloads of the
263
- /// Subscription constructor.
264
- ///</para>
265
- ///<para>
266
- /// Calling Bind() multiple times to bind to multiple
267
- /// exchanges, or to bind to a single exchange more than once
268
- /// with a different routingKey, is perfectly
269
- /// acceptable. Calling Bind() twice with exactly the same
270
- /// arguments is permitted and idempotent. For details, see
271
- /// the AMQP specification.
272
- ///</para>
273
- ///</remarks>
274
- public void Bind ( string exchangeName , string exchangeType , string routingKey )
275
- {
276
- m_model . ExchangeDeclare ( exchangeName , exchangeType ) ;
277
- m_model . QueueBind ( m_queueName , exchangeName , routingKey , false , null ) ;
278
- }
279
-
280
169
///<summary>If LatestEvent is non-null, passes it to
281
170
///Ack(BasicDeliverEventArgs). Causes LatestEvent to become
282
171
///null.</summary>
0 commit comments