本文整理汇总了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;
}