title: RabbitMQ suspend queue consumption
body: <p>What is the best way to keep a durable queue and its bindings but suspend its consumers?</p>
  
  <p>The use case is: I would like to "let it crash" and stop handling messages if we keep getting a bunch of messages we can't deal with (e.g. the database is down or schema issue) but would like to keep aggregating to the queue. That is allow publish but suspend consuming. </p>
  
  <p>I can think of three solutions:</p>
  
  <ol>
  <li>I could have all the consumers bound to the queue continuously reject the messages and re-queue but this is sort of waste resources not to mention I have programmatically do the above logic.</li>
  <li>I could call <code>basic.cancelConsumer</code> on all the consumers (see below)</li>
  <li>Or in terms of <a href="/questions/tagged/spring-amqp" class="post-tag" title="show questions tagged 'spring-amqp'" rel="tag">spring-amqp</a> I guess I could call <code>shutdown</code> on all the <a href="http://static.springsource.org/spring-amqp/api/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainer.html" rel="noreferrer">SimpleMessageListenerContainers</a> that are bound to the queue.</li>
  </ol>
  
  <p><code>#1</code> we are already doing as the messages are getting rejected. The problem is this ends up being like an infinite while loop of failure and if your logging that failure even more resources are wasted.</p>
  
  <p><code>#3</code> seems ideal but I have to some how have know about all the message listeners and then notify them to shutdown. I suppose I could use a fanout exchange to notify that the queue needs to be suspended. I feel like RabbitMQ must have something built-in for this logic. The other issue is that you can bind multiple queues to a message container (not all queues may need to be suspended).</p>
  
  <p>For <code>#2</code> I know I can <a href="http://www.rabbitmq.com/releases/rabbitmq-java-client/v3.0.3/rabbitmq-java-client-javadoc-3.0.3/com/rabbitmq/client/Channel.html#basicCancel%28java.lang.String%29" rel="noreferrer">cancel the consumer</a> with its <code>consumerTag</code> but the question (assuming that is the right way to do the above) is where do I get the list of <code>consumerTag</code>s to a queue?  </p>