本文整理匯總了Java中com.rabbitmq.client.ConnectionFactory.setHandshakeTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java ConnectionFactory.setHandshakeTimeout方法的具體用法?Java ConnectionFactory.setHandshakeTimeout怎麽用?Java ConnectionFactory.setHandshakeTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.rabbitmq.client.ConnectionFactory
的用法示例。
在下文中一共展示了ConnectionFactory.setHandshakeTimeout方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: create
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
static ConnectionProvider create(final RabbitMqConfig config, final DefaultSslConfigurator sslConfigurator) {
final ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setUsername(config.username());
connectionFactory.setPassword(config.password());
connectionFactory.setVirtualHost(config.virtualHost());
connectionFactory.setAutomaticRecoveryEnabled(config.networkRecoveryEnabled());
connectionFactory.setTopologyRecoveryEnabled(config.topologyRecoveryEnabled());
connectionFactory.setConnectionTimeout((int) config.connectionTimeout().toMillis());
connectionFactory.setHandshakeTimeout((int) config.handshakeTimeout().toMillis());
connectionFactory.setShutdownTimeout((int) config.shutdownTimeout().toMillis());
connectionFactory.setNetworkRecoveryInterval(config.networkRecoveryInterval().toMillis());
connectionFactory.setRequestedHeartbeat((int) config.heartbeat().getSeconds());
connectionFactory.setRequestedChannelMax(config.channelLimit());
connectionFactory.setRequestedFrameMax(config.frameSizeLimit());
if (config.nonBlockingIoEnabled()) {
connectionFactory.useNio();
} else {
connectionFactory.useBlockingIo();
}
if (config.sslEnabled()) {
sslConfigurator.configure(connectionFactory, config);
}
return new RabbitConnectionProvider(config, connectionFactory);
}
示例2: createConnection
import com.rabbitmq.client.ConnectionFactory; //導入方法依賴的package包/類
private synchronized Connection createConnection(ChannelType connectionType) throws ConnectionFailureException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startTime = new Date();
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
settings.getClient_properties().put("connection_type", connectionType.toString());
settings.getClient_properties().put("connect_time", sdf.format(startTime)+"Z");
ConnectionFactory cf = new ConnectionFactory();
cf.setRequestedHeartbeat(settings.getHeartbeat());
cf.setConnectionTimeout(settings.getConnection_timeout_millis());
cf.setShutdownTimeout(settings.getShutdown_timeout_millis());
cf.setRequestedFrameMax(settings.getFrame_max());
cf.setHandshakeTimeout(settings.getHandshake_timeout_millis());
cf.setClientProperties((Map)settings.getClient_properties());
//cf.setSocketConfigurator(); NOTE is this worth investigating??
cf.setRequestedChannelMax(0);//Hard coded ..
cf.setAutomaticRecoveryEnabled(false);//Hard coded ..
cf.setTopologyRecoveryEnabled(false);//Hard coded ..
Exception lastException = null;
Connection connection = null;
for (BrokerAddresses.BrokerAddress address : addresses) {
cf.setPassword(address.password);
cf.setUsername(address.username);
cf.setPort(address.port);
cf.setHost(address.host);
cf.setVirtualHost(address.virtualHost);
try {
if(address.scheme.toLowerCase().equals("amqps")){
cf.useSslProtocol();
cf.setSocketFactory(SSLSocketFactory.getDefault()); //Because rabbit uses NoopTrustStore by default...
}
log.infoWithParams("Creating "+connectionType+" connection to broker ...",
"address", address.toString(),
"settings", settings.toString());
connection = cf.newConnection();
boolean isOpen = connection.isOpen();
if(!isOpen){
continue;
}
break;
} catch (Exception e) {
log.debugWithParams("Failed to createConnection to broker",
"address", address.toString());
lastException = e;
}
}
if(connection == null){
throw new ConnectionFailureException(cf, lastException);
}
conToChannel.put(connectionType,
new ConnectionInfo(
connection,
new ArrayList<ChannelImpl>(),
settings.getClient_properties(),
connectionType)
);
log.infoWithParams("Successfully created "+connectionType+" connection to broker.",
"address", addresses.get(0).toString(),
"localPort", ((AMQConnection) connection).getLocalPort(),
"settings", settings.toString());
return connection;
}