List of usage examples for com.rabbitmq.client ConnectionFactory setHandshakeTimeout
public void setHandshakeTimeout(int timeout)
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 {//from w w w . ja v a2 s.com 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./*from ww w . j a va 2 s . com*/ */ 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:org.thingsboard.rule.engine.rabbitmq.TbRabbitMqNode.java
License:Apache License
@Override public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { this.config = TbNodeUtils.convert(configuration, TbRabbitMqNodeConfiguration.class); ConnectionFactory factory = new ConnectionFactory(); factory.setHost(this.config.getHost()); factory.setPort(this.config.getPort()); factory.setVirtualHost(this.config.getVirtualHost()); factory.setUsername(this.config.getUsername()); factory.setPassword(this.config.getPassword()); factory.setAutomaticRecoveryEnabled(this.config.isAutomaticRecoveryEnabled()); factory.setConnectionTimeout(this.config.getConnectionTimeout()); factory.setHandshakeTimeout(this.config.getHandshakeTimeout()); this.config.getClientProperties().forEach((k, v) -> factory.getClientProperties().put(k, v)); try {/* w w w . j a va 2 s. c om*/ this.connection = factory.newConnection(); this.channel = this.connection.createChannel(); } catch (Exception e) { throw new TbNodeException(e); } }
From source file:ws.ament.hammock.rabbitmq.ConnectionFactoryProducer.java
License:Apache License
@Produces @ApplicationScoped// w w w.j a va 2 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; }