Java Code Examples for com.rabbitmq.client.Connection#addShutdownListener()
The following examples show how to use
com.rabbitmq.client.Connection#addShutdownListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RabbitMQEventBus.java From cloudstack with Apache License 2.0 | 8 votes |
private synchronized Connection createConnection() throws KeyManagementException, NoSuchAlgorithmException, IOException, TimeoutException { 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; }
Example 2
Source File: RabbitMetricsBinder.java From summerframework with Apache License 2.0 | 6 votes |
@Override public void newConnection(final Connection connection) { try { if (connection.getId() == null) { connection.setId(UUID.randomUUID().toString()); } connections.incrementAndGet(); connectionState.put(connection.getId(), new RabbitMetricsBinder.ConnectionState(connection)); connection.addShutdownListener(new ShutdownListener() { @Override public void shutdownCompleted(ShutdownSignalException cause) { closeConnection(connection); } }); } catch (Exception e) { LOGGER.info("Error while computing metrics in newConnection: " + e.getMessage()); } }
Example 3
Source File: RabbitMQConsumer.java From storm-rabbitmq with MIT License | 5 votes |
private Connection createConnection() throws IOException, TimeoutException { Connection connection = highAvailabilityHosts == null || highAvailabilityHosts.length == 0 ? connectionFactory.newConnection() : connectionFactory.newConnection(highAvailabilityHosts); connection.addShutdownListener(new ShutdownListener() { @Override public void shutdownCompleted(ShutdownSignalException cause) { logger.error("shutdown signal received", cause); reporter.reportError(cause); reset(); } }); logger.info("connected to rabbitmq: " + connection + " for " + queueName); return connection; }