Example usage for com.rabbitmq.client ConnectionFactory setThreadFactory

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

Introduction

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

Prototype

public void setThreadFactory(ThreadFactory threadFactory) 

Source Link

Document

Set the thread factory used to instantiate new threads.

Usage

From source file:kieker.monitoring.writer.amqp.AmqpWriter.java

License:Apache License

private Connection createConnection() throws KeyManagementException, NoSuchAlgorithmException,
        URISyntaxException, IOException, TimeoutException {
    final ConnectionFactory connectionFactory = new ConnectionFactory();

    connectionFactory.setUri(this.uri);
    connectionFactory.setRequestedHeartbeat(this.heartbeat);
    // Use only daemon threads for connections. Otherwise, all connections would have to be explicitly
    // closed for the JVM to terminate.
    connectionFactory.setThreadFactory(new DaemonThreadFactory());

    return connectionFactory.newConnection();
}

From source file:org.smartdeveloperhub.curator.connector.BrokerController.java

License:Apache License

void connect() throws ControllerException {
    this.write.lock();
    try {/*  w w w  .  j  av  a 2s.c om*/
        if (this.connected) {
            return;
        }
        final ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(this.broker.host());
        factory.setPort(this.broker.port());
        factory.setVirtualHost(this.broker.virtualHost());
        factory.setThreadFactory(brokerThreadFactory());
        factory.setExceptionHandler(new BrokerControllerExceptionHandler(this));
        this.connection = factory.newConnection();
        createChannel();
    } catch (IOException | TimeoutException e) {
        this.connected = false;
        final String message = String.format("Could not connect to broker at %s:%s using virtual host %s",
                this.broker.host(), this.broker.port(), this.broker.virtualHost());
        throw new ControllerException(message, e);
    } finally {
        this.write.unlock();
    }
}

From source file:org.smartdeveloperhub.harvesters.it.notification.ConnectionManager.java

License:Apache License

void connect() throws ControllerException {
    this.lock.lock();
    try {//  www.  j av a  2s  .c o m
        if (connected()) {
            return;
        }
        final ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(this.brokerHost);
        factory.setPort(this.brokerPort);
        factory.setVirtualHost(this.virtualHost);
        factory.setThreadFactory(brokerThreadFactory());
        factory.setExceptionHandler(new ConnectionManagerExceptionHandler(this));
        this.connection = factory.newConnection();
        createChannel();
    } catch (IOException | TimeoutException e) {
        final String message = String.format("Could not connect to broker at %s:%s using virtual host %s",
                this.brokerHost, this.brokerPort, this.virtualHost);
        throw new ControllerException(this.brokerHost, this.brokerPort, this.virtualHost, message, e);
    } finally {
        this.lock.unlock();
    }
}

From source file:ox.softeng.burst.service.message.RabbitMessageService.java

public RabbitMessageService(EntityManagerFactory emf, Properties properties)
        throws IOException, TimeoutException {

    exchange = properties.getProperty("rabbitmq.exchange");
    queue = properties.getProperty("rabbitmq.queue");
    entityManagerFactory = emf;/*from   www  . j  a  va2 s . co  m*/
    consumerCount = Utils.convertToInteger("message.service.thread.size",
            properties.getProperty("message.service.consumer.size"), 1);

    String host = properties.getProperty("rabbitmq.host");
    String username = properties.getProperty("rabbitmq.user", ConnectionFactory.DEFAULT_USER);
    String password = properties.getProperty("rabbitmq.password", ConnectionFactory.DEFAULT_PASS);
    Integer port = Utils.convertToInteger("rabbitmq.port", properties.getProperty("rabbitmq.port"),
            ConnectionFactory.DEFAULT_AMQP_PORT);

    ConnectionFactory factory = new ConnectionFactory();
    factory.setUsername(username);
    factory.setPassword(password);
    factory.setPort(port);
    factory.setHost(host);
    factory.setAutomaticRecoveryEnabled(true);
    factory.setThreadFactory(new NamedThreadFactory("consumer"));

    connection = factory.newConnection();

    logger.info("Creating new RabbitMQ Service using: \n" + "  host: {}:{}\n" + "  user: {}\n"
            + "  exchange: {}\n" + "  queue: {}", host, port, username, exchange, queue);
}

From source file:ws.ament.hammock.rabbitmq.ConnectionFactoryProducer.java

License:Apache License

@Produces
@ApplicationScoped/*from  w  w  w .  ja v a2 s .co m*/
public ConnectionFactory createConnectionFactory(RabbitMQConfiguration rabbitMQConfiguration) {
    ConnectionFactory connectionFactory = new ConnectionFactory();
    connectionFactory.setAutomaticRecoveryEnabled(rabbitMQConfiguration.isAutomaticRecovery());
    connectionFactory.setClientProperties(rabbitMQConfiguration.getClientProperties());
    connectionFactory.setConnectionTimeout(rabbitMQConfiguration.getConnectionTimeout());
    connectionFactory.setExceptionHandler(rabbitMQConfiguration.getExceptionHandler());
    connectionFactory.setHandshakeTimeout(rabbitMQConfiguration.getHandshakeTimeout());
    connectionFactory.setHeartbeatExecutor(rabbitMQConfiguration.getHeartbeatExecutor());
    connectionFactory.setMetricsCollector(rabbitMQConfiguration.getMetricsCollector());
    connectionFactory.setHost(rabbitMQConfiguration.getHost());
    connectionFactory.setNetworkRecoveryInterval(rabbitMQConfiguration.getNetworkRecoveryInterval());
    if (rabbitMQConfiguration.isNio()) {
        connectionFactory.useNio();
        connectionFactory.setNioParams(rabbitMQConfiguration.getNioParams());
    }
    connectionFactory.setPassword(rabbitMQConfiguration.getPassword());
    connectionFactory.setPort(rabbitMQConfiguration.getPort());
    connectionFactory.setRequestedChannelMax(rabbitMQConfiguration.getRequestedChannelMax());
    connectionFactory.setRequestedFrameMax(rabbitMQConfiguration.getRequestedFrameMax());
    connectionFactory.setRequestedHeartbeat(rabbitMQConfiguration.getRequestedHeartbeat());
    connectionFactory.setSaslConfig(rabbitMQConfiguration.getSaslConfig());
    connectionFactory.setSharedExecutor(rabbitMQConfiguration.getSharedExecutor());
    connectionFactory.setShutdownExecutor(rabbitMQConfiguration.getShutdownExecutor());
    connectionFactory.setShutdownTimeout(rabbitMQConfiguration.getShutdownTimeout());
    connectionFactory.setSocketConfigurator(rabbitMQConfiguration.getSocketConf());
    connectionFactory.setSocketFactory(rabbitMQConfiguration.getFactory());
    connectionFactory.setThreadFactory(rabbitMQConfiguration.getThreadFactory());
    connectionFactory.setTopologyRecoveryEnabled(rabbitMQConfiguration.isTopologyRecovery());
    try {
        connectionFactory.setUri(rabbitMQConfiguration.getUri());
    } catch (Exception e) {
        throw new RuntimeException("Unable to populate URI ", e);
    }
    connectionFactory.setUsername(rabbitMQConfiguration.getUsername());
    connectionFactory.setVirtualHost(rabbitMQConfiguration.getVirtualHost());
    if (rabbitMQConfiguration.getSslContext() != null) {
        connectionFactory.useSslProtocol(rabbitMQConfiguration.getSslContext());
    }
    return connectionFactory;
}