/**
  * Public API - cancels the consumer, thus deleting the queue, if it was a temporary queue, and
  * marks the RpcServer as closed.
  *
  * @throws IOException if an error is encountered
  */
 public void close() throws IOException {
   if (_consumer != null) {
     _channel.basicCancel(_consumer.getConsumerTag());
     _consumer = null;
   }
   terminateMainloop();
 }
 public void testDeclarationOfManyAutoDeleteQueuesWithTransientConsumer()
     throws IOException, TimeoutException {
   Channel ch = connection.createChannel();
   assertRecordedQueues(connection, 0);
   for (int i = 0; i < 5000; i++) {
     String q = UUID.randomUUID().toString();
     ch.queueDeclare(q, false, false, true, null);
     QueueingConsumer dummy = new QueueingConsumer(ch);
     String tag = ch.basicConsume(q, true, dummy);
     ch.basicCancel(tag);
   }
   assertRecordedQueues(connection, 0);
   ch.close();
 }
 public void close() {
   try {
     if (channel != null && channel.isOpen()) {
       if (consumerTag != null) channel.basicCancel(consumerTag);
       channel.close();
     }
   } catch (Exception e) {
     logger.debug("error closing channel and/or cancelling consumer", e);
   }
   try {
     logger.info("closing connection to rabbitmq: " + connection);
     connection.close();
   } catch (Exception e) {
     logger.debug("error closing connection", e);
   }
   consumer = null;
   consumerTag = null;
   channel = null;
   connection = null;
 }