title: Delete ActiveMQ queue after stopping a Camel Route
body: <p>I have an issue on deleting an ActiveMQ queue because due to the error</p>
  
  <pre><code>Destination   still has an active subscription: queue://MyQueue
  </code></pre>
  
  <p>The reason is that there's a consumer attached to the queue, this is what I see from the ActiveMQ console, but the consumer should not be there and be active (IMHO, but having the issue I'm surely wrong), because :</p>
  
  <p>T0 : queue MyQueue having messages and no consumer attached<br>
  T1 : a Spring TaskScheduler execute a code that create a Camel Route in charge to move messages in another queue with this code</p>
  
  <pre><code>....
  //context is a CamelContext instance autowired
  context.addRoutes(new RouteBuilder() {
  
          public void configure() {
  
              from(myQueueURI)
              .id(myQueueURI)
              .to(destinationQueueURI);                       
          }
  </code></pre>
  
  <p>T2 : on a specific fixed interval, another Spring TaskScheduler is in charge to query MyQueue in order to understand if it's empty, and in this case, try to remove the queue.</p>
  
  <pre><code>....
  ....
  @Autowired
  public CachingConnectionFactory localCachingConnectionFactory;
  ....
  ....
  removeCamelRoutes(queueName, routeId);
  
  private boolean removeCamelRoutes(String queueName, String routeId) throws JMSException{
  
          if (isQueueEmpty(queueName)){
              try {
                  //context is a CamelContext instance autowired
                  context.stopRoute(routeId);
                  context.removeRoute(routeId);
                  deleteQueue(queueName);
              } catch (Exception e) {
                  //logs 
                  return false;
              }
          }
          ....
          ....
  }
  
  private boolean isQueueEmpty(String queueName) throws JMSException{
      ActiveMQConnectionFactory activeMQConnectionFactory = (ActiveMQConnectionFactory) localCachingConnectionFactory.getTargetConnectionFactory();
      ActiveMQConnection connection = (ActiveMQConnection) activeMQConnectionFactory.createConnection();
      connection.start();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      ActiveMQQueue queue = (ActiveMQQueue) session.createQueue(queueName);
      QueueBrowser queueBrowser = session.createBrowser(queue);
      try {
          if (queueBrowser.getEnumeration().hasMoreElements()){
              queueBrowser.close();
              return false;
          }
          return true;
      }
      finally {
          if (queueBrowser != null) {
              queueBrowser.close();       
          }
          session.close();
          connection.close();
      }
  }
  
  
  private void deleteQueue(String queueName) throws Exception {
  
      ActiveMQConnectionFactory activeMQConnectionFactory = (ActiveMQConnectionFactory) localCachingConnectionFactory.getTargetConnectionFactory();
      ActiveMQConnection connection = (ActiveMQConnection) activeMQConnectionFactory.createConnection();
      connection.start();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      ActiveMQQueue queue = (ActiveMQQueue) session.createQueue(queueName);
  
      try {
          //HERE is where the operation is failing
          connection.destroyDestination(queue);
      } 
      finally {
          session.close();
          connection.close();
      }
  
  }
  </code></pre>
  
  <p>I ask for some hints on where I miss something about the still alive consumer, I was thinking about the consumer related to Camel Route but it should be closed automatically with the Route, it could be the consumer attached on querying the queue, but I should have closed correctly Session and Connection.</p>
  
  <p>Camel version 2.15.1, ActiveMQ 5.9.0, Spring 4.1.3</p>
  
  <p>Thanks a lot in advance.</p>