Skip to content

Commit f759a31

Browse files
committed
Merge bug21263 into default
2 parents 77bb034 + 2bf6b75 commit f759a31

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

src/com/rabbitmq/client/Channel.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,27 @@ Queue.DeclareOk queueDeclare(String queue, boolean passive, boolean durable, boo
355355
*/
356356
Queue.UnbindOk queueUnbind(String queue, String exchange, String routingKey, Map<String, Object> arguments) throws IOException;
357357

358+
/**
359+
* Purges the contents of the given queue and awaits a completion.
360+
* @see com.rabbitmq.client.AMQP.Queue.Purge
361+
* @see com.rabbitmq.client.AMQP.Queue.PurgeOk
362+
* @param queue the name of the queue
363+
* @return a purge-confirm method if the purge was executed succesfully
364+
* @throws java.io.IOException if an error is encountered
365+
*/
366+
Queue.PurgeOk queuePurge(String queue) throws IOException;
367+
368+
/**
369+
* Purges the contents of the given queue.
370+
* @see com.rabbitmq.client.AMQP.Queue.Purge
371+
* @see com.rabbitmq.client.AMQP.Queue.PurgeOk
372+
* @param queue the name of the queue
373+
* @param nowait whether to await completion of the purge
374+
* @return a purge-confirm method if the purge was executed succesfully
375+
* @throws java.io.IOException if an error is encountered
376+
*/
377+
Queue.PurgeOk queuePurge(String queue, boolean nowait) throws IOException;
378+
358379
/**
359380
* Retrieve a message from a queue using {@link com.rabbitmq.client.AMQP.Basic.Get}
360381
* @see com.rabbitmq.client.AMQP.Basic.Get

src/com/rabbitmq/client/impl/ChannelN.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,21 @@ public Queue.UnbindOk queueUnbind(String queue, String exchange, String routingK
522522
arguments)).getMethod();
523523
}
524524

525+
/** Public API - {@inheritDoc} */
526+
public Queue.PurgeOk queuePurge(String queue)
527+
throws IOException
528+
{
529+
return queuePurge(queue, false);
530+
}
531+
532+
/** Public API - {@inheritDoc} */
533+
public Queue.PurgeOk queuePurge(String queue, boolean nowait)
534+
throws IOException
535+
{
536+
return (Queue.PurgeOk)
537+
exnWrappingRpc(new Queue.Purge(TICKET, queue, nowait)).getMethod();
538+
}
539+
525540
/** Public API - {@inheritDoc} */
526541
public Queue.UnbindOk queueUnbind(String queue, String exchange, String routingKey)
527542
throws IOException

test/src/com/rabbitmq/client/test/functional/BindingLifecycle.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,23 @@ public void testQueueDelete() throws IOException {
211211
deleteExchangeAndQueue(binding);
212212
}
213213

214+
/**
215+
* This tests that when you purge a queue, all of its messages go.
216+
*/
217+
public void testQueuePurge() throws IOException {
218+
219+
Binding binding = setupExchangeBindings(false);
220+
channel.basicPublish(binding.x, binding.k, null, payload);
221+
222+
// Purge the queue, and test that we don't recieve a message
223+
channel.queuePurge(binding.q);
224+
225+
GetResponse response = channel.basicGet(binding.q, true);
226+
assertNull("The response SHOULD BE null", response);
227+
228+
deleteExchangeAndQueue(binding);
229+
}
230+
214231
/**
215232
* This tests whether when you delete an exchange, that any
216233
* bindings attached to it are deleted as well.

0 commit comments

Comments
 (0)