Example #1
0
  private Connection _newConnection(int numThreads) throws IOException {
    ConnectionFactory connFactory = new ConnectionFactory();
    ThreadFactory threadFactory = DaemonThreadFactory.getInstance("RabbitMQ-ConsumerThread", true);
    final ExecutorService executor = Executors.newFixedThreadPool(numThreads, threadFactory);
    Address[] array = addresses.toArray(new Address[0]);
    Connection conn = connFactory.newConnection(executor, array);

    conn.addShutdownListener(
        new ShutdownListener() {
          @Override
          public void shutdownCompleted(ShutdownSignalException sse) {
            executor.shutdown();
          }
        });

    return conn;
  }