Example usage for com.rabbitmq.client ConnectionFactory newConnection

List of usage examples for com.rabbitmq.client ConnectionFactory newConnection

Introduction

In this page you can find the example usage for com.rabbitmq.client ConnectionFactory newConnection.

Prototype

public Connection newConnection(ExecutorService executor, String connectionName)
        throws IOException, TimeoutException 

Source Link

Document

Create a new broker connection.

Usage

From source file:com.shopwiki.roger.RabbitConnector.java

License:Apache License

private Connection _getConnection(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/*from ww  w  . j  ava  2  s .com*/
        public void shutdownCompleted(ShutdownSignalException sse) {
            executor.shutdown();
        }
    });

    return conn;
}

From source file:org.apache.synapse.transport.amqp.connectionfactory.AMQPTransportConnectionFactory.java

License:Apache License

private Connection createConnection(ExecutorService es, Map<String, String> parameters)
        throws IOException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException {
    ConnectionFactory connectionFactory = new ConnectionFactory();
    connectionFactory.setUri(parameters.get(AMQPTransportConstant.PARAMETER_CONNECTION_URI));

    if (parameters.get(AMQPTransportConstant.PARAMETER_BROKER_LIST) != null) {
        Address[] addresses = AMQPTransportUtils
                .getAddressArray(parameters.get(AMQPTransportConstant.PARAMETER_BROKER_LIST), ",", ':');
        return connectionFactory.newConnection(es, addresses);
    }//from  ww w .  ja  va2  s  . c om
    return connectionFactory.newConnection(es);
}