List of usage examples for com.rabbitmq.client ConnectionFactory setShutdownTimeout
public void setShutdownTimeout(int shutdownTimeout)
From source file:io.bootique.rabbitmq.client.connection.ConnectionConfig.java
License:Apache License
public Connection createConnection(String connectionName) { com.rabbitmq.client.ConnectionFactory factory = createConnectionFactory(); factory.setRequestedChannelMax(requestedChannelMax); factory.setRequestedFrameMax(requestedFrameMax); factory.setRequestedHeartbeat(requestedHeartbeat); factory.setConnectionTimeout(connectionTimeout); factory.setHandshakeTimeout(handshakeTimeout); factory.setShutdownTimeout(shutdownTimeout); factory.setAutomaticRecoveryEnabled(automaticRecoveryEnabled); factory.setTopologyRecoveryEnabled(topologyRecovery); factory.setNetworkRecoveryInterval(networkRecoveryInterval); LOGGER.info("Creating RabbitMQ connection."); try {//w w w. j a v a 2 s . c o m return factory.newConnection(); } catch (IOException | TimeoutException e) { throw new RuntimeException(String.format("Can't create connection \"%s\".", connectionName), e); } }
From source file:org.ballerinalang.messaging.rabbitmq.util.ConnectionUtils.java
License:Open Source License
/** * Creates a RabbitMQ Connection using the given connection parameters. * * @param connectionConfig Parameters used to initialize the connection. * @return RabbitMQ Connection object./*w w w . j a va2 s .c o m*/ */ public static Connection createConnection(BMap<String, BValue> connectionConfig) { try { ConnectionFactory connectionFactory = new ConnectionFactory(); String host = RabbitMQUtils.getStringFromBValue(connectionConfig, RabbitMQConstants.RABBITMQ_CONNECTION_HOST); connectionFactory.setHost(host); int port = RabbitMQUtils.getIntFromBValue(connectionConfig, RabbitMQConstants.RABBITMQ_CONNECTION_PORT, LOGGER); connectionFactory.setPort(port); if (connectionConfig.get(RabbitMQConstants.RABBITMQ_CONNECTION_USER) != null) { connectionFactory.setUsername(RabbitMQUtils.getStringFromBValue(connectionConfig, RabbitMQConstants.RABBITMQ_CONNECTION_USER)); } if (connectionConfig.get(RabbitMQConstants.RABBITMQ_CONNECTION_PASS) != null) { connectionFactory.setPassword(RabbitMQUtils.getStringFromBValue(connectionConfig, RabbitMQConstants.RABBITMQ_CONNECTION_PASS)); } if (connectionConfig.get(RabbitMQConstants.RABBITMQ_CONNECTION_TIMEOUT) != null) { connectionFactory.setConnectionTimeout(RabbitMQUtils.getIntFromBValue(connectionConfig, RabbitMQConstants.RABBITMQ_CONNECTION_TIMEOUT, LOGGER)); } if (connectionConfig.get(RabbitMQConstants.RABBITMQ_CONNECTION_HANDSHAKE_TIMEOUT) != null) { connectionFactory.setHandshakeTimeout(RabbitMQUtils.getIntFromBValue(connectionConfig, RabbitMQConstants.RABBITMQ_CONNECTION_HANDSHAKE_TIMEOUT, LOGGER)); } if (connectionConfig.get(RabbitMQConstants.RABBITMQ_CONNECTION_SHUTDOWN_TIMEOUT) != null) { connectionFactory.setShutdownTimeout(RabbitMQUtils.getIntFromBValue(connectionConfig, RabbitMQConstants.RABBITMQ_CONNECTION_SHUTDOWN_TIMEOUT, LOGGER)); } if (connectionConfig.get(RabbitMQConstants.RABBITMQ_CONNECTION_HEARTBEAT) != null) { connectionFactory.setRequestedHeartbeat(RabbitMQUtils.getIntFromBValue(connectionConfig, RabbitMQConstants.RABBITMQ_CONNECTION_HEARTBEAT, LOGGER)); } return connectionFactory.newConnection(); } catch (IOException | TimeoutException exception) { LOGGER.error(RabbitMQConstants.CREATE_CONNECTION_ERROR, exception); throw new RabbitMQConnectorException(RabbitMQConstants.CREATE_CONNECTION_ERROR + exception.getMessage(), exception); } }
From source file:ws.ament.hammock.rabbitmq.ConnectionFactoryProducer.java
License:Apache License
@Produces @ApplicationScoped/*from ww w . j a v a 2 s. c o 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; }