/**
   * Remove any old message queues that have a 0 message count in them. This lets us not worry about
   * changing around the registered listeners.
   */
  private void cleanupOldQueues() {
    log.debug("Cleaning old message queues");
    try {
      String[] queues = hornetqServer.getHornetQServer().getHornetQServerControl().getQueueNames();

      ServerLocator locator =
          HornetQClient.createServerLocatorWithoutHA(
              new TransportConfiguration(InVMConnectorFactory.class.getName()));

      ClientSessionFactory factory = locator.createSessionFactory();
      ClientSession session = factory.createSession(true, true);
      session.start();

      for (int i = 0; i < queues.length; i++) {
        long msgCount = session.queueQuery(new SimpleString(queues[i])).getMessageCount();
        if (msgCount == 0) {
          log.debug(String.format("found queue '%s' with 0 messages. deleting", queues[i]));
          session.deleteQueue(queues[i]);
        } else {
          log.debug(String.format("found queue '%s' with %d messages. kept", queues[i], msgCount));
        }
      }

      session.stop();
      session.close();
    } catch (HornetQException e) {
      log.error("Problem cleaning old message queues:", e);
      throw new RuntimeException(e);
    } catch (Exception e) {
      log.error("Problem cleaning old message queues:", e);
      throw new RuntimeException(e);
    }
  }
 public void stop() throws HornetQException {
   producer.close();
   producerSession.stop();
   producerSession.close();
 }