RabbitMQ的失败重连

异常重连

    public void start() {
        try {
            connection = factory.newConnection();
            connection.addShutdownListener(this);
            LOGGER.info("Connected to " + factory.getHost() + ":" + factory.getPort());
        } catch (final Exception e) {
            LOGGER.log(Level.SEVERE, "Failed to connect to " + factory.getHost() + ":" + factory.getPort(), e);
            asyncWaitAndReconnect();
        }
    }

shutdown

    @Override
    public void shutdownCompleted(final ShutdownSignalException cause) {
        // reconnect only on unexpected errors
        if (!cause.isInitiatedByApplication()) {
            LOGGER.log(Level.SEVERE, "Lost connection to " + factory.getHost() + ":" + factory.getPort(),
                    cause);
 
            connection = null;
            asyncWaitAndReconnect();
        }
    }

定时start

    protected void asyncWaitAndReconnect() {
        executor.schedule(new Runnable() {
            @Override
            public void run() {
                start();
            }
        }, 15, TimeUnit.SECONDS);
    }

你可能感兴趣的:(大数据,javascript,ViewUI)