Skip to content

Commit 743e3fa

Browse files
author
Alexandru Scvortov
committed
removed queue/exchange declaration from Subscription
1 parent eb17047 commit 743e3fa

File tree

2 files changed

+11
-123
lines changed

2 files changed

+11
-123
lines changed

projects/client/RabbitMQ.Client/src/client/messagepatterns/SimpleRpcClient.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,16 @@ namespace RabbitMQ.Client.MessagePatterns {
8787
/// SimpleRpcClient client =
8888
/// new SimpleRpcClient(ch, queueName);
8989
/// client.TimeoutMilliseconds = 5000; // optional
90-
///
90+
///
9191
/// /// ... make use of the various Call() overloads
9292
/// }
9393
/// }
9494
///</code></example>
9595
///<para>
96-
/// Instances of this class do not themselves declare any
97-
/// resources (exchanges, queues or bindings). The Subscription we
98-
/// use for receiving RPC replies declares its own resources
99-
/// (usually a single queue), but if we are sending to an exchange
100-
/// other than one of the AMQP-standard mandated predefined
101-
/// exchanges, it is the user's responsibility to ensure that the
102-
/// exchange concerned exists (using IModel.ExchangeDeclare)
103-
/// before invoking Call() or Cast().
96+
/// Instances of this class declare a queue, so it is the user's
97+
/// responsibility to ensure that the exchange concerned exists
98+
/// (using IModel.ExchangeDeclare) before invoking Call() or
99+
/// Cast().
104100
///</para>
105101
///<para>
106102
/// This class implements only a few basic RPC message formats -
@@ -235,7 +231,8 @@ public void Close()
235231
protected virtual void EnsureSubscription()
236232
{
237233
if (m_subscription == null) {
238-
m_subscription = new Subscription(m_model);
234+
string queueName = m_model.QueueDeclare();
235+
m_subscription = new Subscription(m_model, queueName);
239236
}
240237
}
241238

projects/client/RabbitMQ.Client/src/client/messagepatterns/Subscription.cs

Lines changed: 4 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ namespace RabbitMQ.Client.MessagePatterns {
7777
/// IEnumerator in, for example, a foreach loop.
7878
///</para>
7979
///<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>
8580
/// Note that if the "noAck" option is enabled (which it is by
8681
/// default), then received deliveries are automatically acked
8782
/// within the server before they are even transmitted across the
@@ -103,7 +98,6 @@ public class Subscription: IEnumerable, IEnumerator, IDisposable {
10398
protected readonly object m_consumerLock = new object();
10499
protected volatile QueueingBasicConsumer m_consumer;
105100
protected string m_consumerTag;
106-
protected volatile bool m_shouldDelete;
107101

108102
///<summary>Retrieve the queue name we have subscribed to. May
109103
///be a server-generated name, depending on how the
@@ -136,147 +130,44 @@ public class Subscription: IEnumerable, IEnumerator, IDisposable {
136130
public BasicDeliverEventArgs LatestEvent { get { return m_latestEvent; } }
137131

138132
///<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>
133+
///consuming from a named queue.</summary>
180134
public Subscription(IModel model, string queueName)
181135
: this(model, queueName, true) {}
182136

183137
///<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>
138+
///both "noAck" mode and the name of the queue.</summary>
202139
public Subscription(IModel model, string queueName, bool noAck)
203140
{
204141
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-
}
142+
// FIXME Check if a queue with queueName exists.
212143
m_consumer = new QueueingBasicConsumer(m_model);
213144
m_consumerTag = m_model.BasicConsume(m_queueName, m_noAck, null, m_consumer);
214145
m_latestEvent = null;
215146
}
216147

217148
///<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>
149+
///record in the server.</summary>
224150
public void Close()
225151
{
226152
try {
227153
bool shouldCancelConsumer = false;
228-
bool shouldDelete = false;
229154

230155
lock (m_consumerLock) {
231156
if (m_consumer != null) {
232157
shouldCancelConsumer = true;
233158
m_consumer = null;
234159
}
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;
241160
}
242161

243162
if (shouldCancelConsumer) {
244163
m_model.BasicCancel(m_consumerTag);
245164
m_consumerTag = null;
246165
}
247-
248-
if (shouldDelete) {
249-
m_model.QueueDelete(m_queueName, false, false, false);
250-
}
251166
} catch (OperationInterruptedException) {
252167
// We don't mind, here.
253168
}
254169
}
255170

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-
280171
///<summary>If LatestEvent is non-null, passes it to
281172
///Ack(BasicDeliverEventArgs). Causes LatestEvent to become
282173
///null.</summary>

0 commit comments

Comments
 (0)