use of com.rabbitmq.client.impl.ConnectionParams in project rabbitmq-java-client by rabbitmq.
the class ConnectionFactory method params.
public ConnectionParams params(ExecutorService consumerWorkServiceExecutor) {
ConnectionParams result = new ConnectionParams();
result.setCredentialsProvider(credentialsProvider);
result.setConsumerWorkServiceExecutor(consumerWorkServiceExecutor);
result.setVirtualHost(virtualHost);
result.setClientProperties(getClientProperties());
result.setRequestedFrameMax(requestedFrameMax);
result.setRequestedChannelMax(requestedChannelMax);
result.setShutdownTimeout(shutdownTimeout);
result.setSaslConfig(saslConfig);
result.setNetworkRecoveryInterval(networkRecoveryInterval);
result.setRecoveryDelayHandler(recoveryDelayHandler);
result.setTopologyRecovery(topologyRecovery);
result.setExceptionHandler(exceptionHandler);
result.setThreadFactory(threadFactory);
result.setHandshakeTimeout(handshakeTimeout);
result.setRequestedHeartbeat(requestedHeartbeat);
result.setShutdownExecutor(shutdownExecutor);
result.setHeartbeatExecutor(heartbeatExecutor);
result.setChannelRpcTimeout(channelRpcTimeout);
result.setChannelShouldCheckRpcResponseType(channelShouldCheckRpcResponseType);
result.setWorkPoolTimeout(workPoolTimeout);
result.setErrorOnWriteListener(errorOnWriteListener);
return result;
}
use of com.rabbitmq.client.impl.ConnectionParams in project rabbitmq-java-client by rabbitmq.
the class ConnectionFactory method newConnection.
/**
* Create a new broker connection with a client-provided name, picking the first available address from
* the list provided by the {@link AddressResolver}.
*
* If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
* is enabled, the connection returned by this method will be {@link Recoverable}. Future
* reconnection attempts will pick a random accessible address provided by the {@link AddressResolver}.
*
* @param executor thread execution service for consumers on the connection
* @param addressResolver discovery service to list potential addresses (hostname/port pairs) to connect to
* @param clientProvidedName application-specific connection name, will be displayed
* in the management UI if RabbitMQ server supports it.
* This value doesn't have to be unique and cannot be used
* as a connection identifier e.g. in HTTP API requests.
* This value is supposed to be human-readable.
* @return an interface to the connection
* @throws java.io.IOException if it encounters a problem
* @see <a href="http://www.rabbitmq.com/api-guide.html#recovery">Automatic Recovery</a>
*/
public Connection newConnection(ExecutorService executor, AddressResolver addressResolver, String clientProvidedName) throws IOException, TimeoutException {
if (this.metricsCollector == null) {
this.metricsCollector = new NoOpMetricsCollector();
}
// make sure we respect the provided thread factory
FrameHandlerFactory fhFactory = createFrameHandlerFactory();
ConnectionParams params = params(executor);
// set client-provided via a client property
if (clientProvidedName != null) {
Map<String, Object> properties = new HashMap<String, Object>(params.getClientProperties());
properties.put("connection_name", clientProvidedName);
params.setClientProperties(properties);
}
if (isAutomaticRecoveryEnabled()) {
// see com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory#newConnection
AutorecoveringConnection conn = new AutorecoveringConnection(params, fhFactory, addressResolver, metricsCollector);
conn.init();
return conn;
} else {
List<Address> addrs = addressResolver.getAddresses();
Exception lastException = null;
for (Address addr : addrs) {
try {
FrameHandler handler = fhFactory.create(addr, clientProvidedName);
AMQConnection conn = createConnection(params, handler, metricsCollector);
conn.start();
this.metricsCollector.newConnection(conn);
return conn;
} catch (IOException e) {
lastException = e;
} catch (TimeoutException te) {
lastException = te;
}
}
if (lastException != null) {
if (lastException instanceof IOException) {
throw (IOException) lastException;
} else if (lastException instanceof TimeoutException) {
throw (TimeoutException) lastException;
}
}
throw new IOException("failed to connect");
}
}
Aggregations