本文整理匯總了Java中com.rabbitmq.client.Connection.addShutdownListener方法的典型用法代碼示例。如果您正苦於以下問題:Java Connection.addShutdownListener方法的具體用法?Java Connection.addShutdownListener怎麽用?Java Connection.addShutdownListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.rabbitmq.client.Connection
的用法示例。
在下文中一共展示了Connection.addShutdownListener方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createConnection
import com.rabbitmq.client.Connection; //導入方法依賴的package包/類
private synchronized Connection createConnection() throws KeyManagementException, NoSuchAlgorithmException, IOException, TimeoutException {
final ConnectionFactory factory = new ConnectionFactory();
factory.setUsername(username);
factory.setPassword(password);
factory.setHost(amqpHost);
factory.setPort(port);
if (virtualHost != null && !virtualHost.isEmpty()) {
factory.setVirtualHost(virtualHost);
} else {
factory.setVirtualHost("/");
}
if (useSsl != null && !useSsl.isEmpty() && useSsl.equalsIgnoreCase("true")) {
factory.useSslProtocol(secureProtocol);
}
final Connection connection = factory.newConnection();
connection.addShutdownListener(disconnectHandler);
connection.addBlockedListener(blockedConnectionHandler);
s_connection = connection;
return s_connection;
}
示例2: createConnection
import com.rabbitmq.client.Connection; //導入方法依賴的package包/類
private synchronized Connection createConnection() throws Exception {
try {
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername(username);
factory.setPassword(password);
factory.setHost(amqpHost);
factory.setPort(port);
if (virtualHost != null && !virtualHost.isEmpty()) {
factory.setVirtualHost(virtualHost);
} else {
factory.setVirtualHost("/");
}
if (useSsl != null && !useSsl.isEmpty() && useSsl.equalsIgnoreCase("true")) {
factory.useSslProtocol(secureProtocol);
}
Connection connection = factory.newConnection();
connection.addShutdownListener(disconnectHandler);
connection.addBlockedListener(blockedConnectionHandler);
s_connection = connection;
return s_connection;
} catch (Exception e) {
throw e;
}
}
示例3: getConnection
import com.rabbitmq.client.Connection; //導入方法依賴的package包/類
private synchronized CachedConnection getConnection(AMQPConnectionParameters connectionParameters)
throws IOException {
String key = connectionParameters.getKey();
CachedConnection connection = cachedConnections.get(key);
if (connection == null) {
logger.debug(String.format("creating a new connection %s", key));
ConnectionFactory factory = new ConnectionFactory();
if (socketFactory != null) {
factory.setSocketFactory(socketFactory);
}
factory.setHost(connectionParameters.getHost());
factory.setPort(connectionParameters.getPort());
factory.setUsername(connectionParameters.getUsername());
factory.setPassword(connectionParameters.getPassword());
factory.setVirtualHost(connectionParameters.getVhost());
Connection c = factory.newConnection();
c.addShutdownListener(new AMQPShutDownListener(c.toString()));
connection = new CachedConnection(this, c);
cachedConnections.put(key, connection);
}
return connection;
}
示例4: create
import com.rabbitmq.client.Connection; //導入方法依賴的package包/類
@Override
public Connection create() throws Exception {
ConnectionFactory factory = null;
Connection connection = null;
do {
try {
factory = pickOne();
connection = factory.newConnection();
} catch (Exception e) {
logger.error("fail to create new connection from factory: [" + factory.getHost() + ":"
+ factory.getPort() + "], kicking this one out and retry...");
kick(factory.getHost() + ":" + factory.getPort());
}
} while (connection == null
&& ConnectionFactoryManager.getInstance().getAvailableFactories().keySet().size() > 0);
if (connection == null) {
throw new Exception("fail to get new connection. no hosts left to use.");
}
/* ADD CONNECTION & CHANNEL CONNECTION LISTENER */
connection.addShutdownListener(new ShutdownListener() {
public void shutdownCompleted(ShutdownSignalException cause) {
String hardError = "";
String applInit = "";
if (cause.isHardError()) {
hardError = "connection";
} else {
hardError = "channel";
}
if (cause.isInitiatedByApplication()) {
applInit = "application";
} else {
applInit = "broker";
}
logger.warn("Connectivity to MQ has failed. It was caused by " + applInit + " at the " + hardError
+ " level. Reason received " + cause.getReason());
}
});
((Recoverable) connection).addRecoveryListener(new RecoveryListener() {
public void handleRecovery(Recoverable recoverable) {
if (recoverable instanceof Connection) {
logger.info("Connection was recovered.");
} else if (recoverable instanceof Channel) {
int channelNumber = ((Channel) recoverable).getChannelNumber();
logger.info("Connection to channel #" + channelNumber + " was recovered.");
}
}
public void handleRecoveryStarted(Recoverable arg0) {
}
});
/* ADD CONNECTION & CHANNEL CONNECTION LISTENER */
logger.info(
"new connection was establesed...from host <- [" + factory.getHost() + ":" + factory.getPort() + "]");
return connection;
}