private ConnectionFactory getConnectionFactory() {
   ActiveMQConnectionFactory activeMQConnectionFactory =
       new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
   CachingConnectionFactory cachingConnectionFactory =
       new CachingConnectionFactory(activeMQConnectionFactory);
   cachingConnectionFactory.setCacheConsumers(false);
   return cachingConnectionFactory;
 }
  @Bean
  public ConnectionFactory amqConnectionFactory() {
    CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
    ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
    activeMQConnectionFactory.setBrokerURL("vm://localhost?broker.persistent=false");

    cachingConnectionFactory.setTargetConnectionFactory(activeMQConnectionFactory);
    cachingConnectionFactory.setSessionCacheSize(10);
    cachingConnectionFactory.setCacheProducers(true);
    cachingConnectionFactory.setReconnectOnException(true);
    return cachingConnectionFactory;
  }
 private boolean checkActiveMQConnection() {
   try {
     connectionFactory.getTargetConnectionFactory().createConnection().start();
     return true;
   } catch (Exception ex) {
   }
   return false;
 }
  // shut down the proxy at end-of-game, wait a few seconds, go again.
  private void recycle() {
    // no longer initialized
    initialized = false;

    // shutdown proxy and force re-creation
    if (proxy != null) {
      log.info("shut down proxy");
      proxy.shutdown();
    }
    proxy = null;

    // force recreation of the connection
    connectionFactory.destroy();

    // wait for sim process to quit
    try {
      Thread.sleep(5000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }