if (cause.isInitiatedByApplication()) { LOG.info("Shutting down AMPQ consumer."); return;
public void shutdownCompleted(ShutdownSignalException cause) { LOGGER.info("shutdown signal received", cause); // Do nothing if SiteWhere initiated the connection close if (!cause.isInitiatedByApplication()) { connection = null; scheduleReconnect(); } } });
@Override public void shutdownCompleted(ShutdownSignalException cause) { if (cause.isInitiatedByApplication()) { return; } log.info("RabbitMQ connection shutdown! The client will attempt to reconnect automatically", cause); }
@Override public void shutdownCompleted(ShutdownSignalException cause) { if (cause.isInitiatedByApplication()) { LOG.info("Not reconnecting connection, we disconnected explicitly."); return; } while (true) { try { LOG.error("AMQP connection lost! Trying reconnect in 1 second."); Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); connect(); LOG.info("Connected! Re-starting consumer."); run(); LOG.info("Consumer running."); break; } catch (IOException e) { LOG.error("Could not re-connect to AMQP broker.", e); } } } });
public void shutdownCompleted(final ShutdownSignalException shutdownSignalException) { if (LOG.isDebugEnabled()) { LOG.debug("Shutdown signal caught: " + shutdownSignalException.getMessage()); } for (HaConnectionListener listener : listeners) { listener.onDisconnect(connectionProxy, shutdownSignalException); } // only try to reconnect if it was a problem with the broker if (!shutdownSignalException.isInitiatedByApplication()) { // start an async reconnection executorService.submit(new ReconnectionTask(true, this, connectionProxy)); } else { if (LOG.isDebugEnabled()) { LOG.debug("Ignoring shutdown signal, application initiated"); } } } }
@Override public void shutdownCompleted(ShutdownSignalException e) { connectionShutdown(); if (!e.isInitiatedByApplication()) { log.error("Connection {} was closed unexpectedly", ConnectionHandler.this); if (canRecover()) RECOVERY_EXECUTORS.execute(new Runnable() { @Override public void run() { try { recoverConnection(); } catch (Exception e) { // Only fail on non-closures since closures will trigger a new recovery if (!Exceptions.isCausedByConnectionClosure(e)) { log.error("Failed to recover connection {}", ConnectionHandler.this, e); connectionClosed(); interruptWaiters(); for (ConnectionListener listener : config.getConnectionListeners()) try { listener.onRecoveryFailure(proxy, e); } catch (Exception ignore) { } } } } }); } else connectionClosed(); } }
@Override public void shutdownCompleted(ShutdownSignalException e) { connectionShutdown(); if (!e.isInitiatedByApplication()) { log.error("Connection {} was closed unexpectedly", ConnectionHandler.this); if (canRecover()) RECOVERY_EXECUTORS.execute(new Runnable() { @Override public void run() { try { recoverConnection(); } catch (Exception e) { // Only fail on non-closures since closures will trigger a new recovery if (!Exceptions.isCausedByConnectionClosure(e)) { log.error("Failed to recover connection {}", ConnectionHandler.this, e); connectionClosed(); interruptWaiters(); for (ConnectionListener listener : config.getConnectionListeners()) try { listener.onRecoveryFailure(proxy, e); } catch (Exception ignore) { } } } } }); } else connectionClosed(); } }
@Override public void shutdownCompleted(ShutdownSignalException cause) { if (cause.isInitiatedByApplication()) { LOG.info("Not reconnecting connection, we disconnected explicitly."); return; } while (true) { try { LOG.error("AMQP connection lost! Trying reconnect in 1 second."); Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); connect(); LOG.info("Connected! Re-starting consumer."); run(); LOG.info("Consumer running."); break; } catch (IOException e) { LOG.error("Could not re-connect to AMQP broker.", e); } } } });
public void shutdownCompleted(ShutdownSignalException cause) { getLogger().info("shutdown signal received", cause); // Do nothing if SiteWhere initiated the connection close if (!cause.isInitiatedByApplication()) { connection = null; scheduleReconnect(); } } });
@Override public void shutdownCompleted(ShutdownSignalException cause) { if ( null==exceptionListener.get() || cause.isInitiatedByApplication() ) return; // Ignore this exceptionListener.get().onException(new RMQJMSException(String.format("error in %s, connection closed, with reason %s", cause.getReference(), cause.getReason()), cause)); } }
/** * No-op implementation of {@link Consumer#handleShutdownSignal}. */ public void handleShutdownSignal(String consumerTag, ShutdownSignalException sig) { log.info("Received shutdown signal on the rabbitMQ channel"); // Check if the consumer closed the connection or something else if (!sig.isInitiatedByApplication()) { // Something else closed the connection so reconnect boolean connected = false; while (!connected && !isStopping()) { try { reconnect(); connected = true; } catch (Exception e) { log.warn("Unable to obtain a RabbitMQ channel. Will try again. Caused by: {}. Stacktrace logged at DEBUG logging level.", e.getMessage()); // include stacktrace in DEBUG logging log.debug(e.getMessage(), e); Integer networkRecoveryInterval = consumer.getEndpoint().getNetworkRecoveryInterval(); final long connectionRetryInterval = networkRecoveryInterval != null && networkRecoveryInterval > 0 ? networkRecoveryInterval : 100L; try { Thread.sleep(connectionRetryInterval); } catch (InterruptedException e1) { Thread.currentThread().interrupt(); } } } } }
@Override public void shutdownCompleted(ShutdownSignalException e) { channelShutdown(); if (!e.isInitiatedByApplication()) { log.error("Channel {} was closed unexpectedly", ChannelHandler.this); lastShutdownSignal = e; if (!Exceptions.isConnectionClosure(e) && canRecover()) ConnectionHandler.RECOVERY_EXECUTORS.execute(new Runnable() { @Override public void run() { try { recoveryPending.set(true); recoverChannel(false); } catch (Throwable ignore) { } } }); } } }
@Override public void shutdownCompleted(ShutdownSignalException e) { channelShutdown(); if (!e.isInitiatedByApplication()) { log.error("Channel {} was closed unexpectedly", ChannelHandler.this); lastShutdownSignal = e; if (!Exceptions.isConnectionClosure(e) && canRecover()) ConnectionHandler.RECOVERY_EXECUTORS.execute(new Runnable() { @Override public void run() { try { recoveryPending.set(true); recoverChannel(false); } catch (Throwable ignore) { } } }); } } }
@Override public void stop() { String cT = this.getConsTag(); logger.trace("consumerTag='{}'", cT); TimeTracker tt = new TimeTracker(this.terminationTimeout, TimeUnit.NANOSECONDS); try { if (!this.completion.isComplete()) { logger.debug("consumerTag='{}' basicCancel:", cT); this.channel.basicCancel(cT); this.completion.waitUntilComplete(tt); this.clearConsTag(); } } catch (TimeoutException te) { Thread.currentThread().interrupt(); } catch (ShutdownSignalException sse) { // TODO check if basicCancel really necessary in this case. if (!sse.isInitiatedByApplication()) { logger.error("basicCancel (consumerTag='{}') threw exception", cT, sse); throw sse; } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (IOException e) { if (! e.getMessage().equals("Unknown consumerTag")) { logger.error("basicCancel (consumerTag='{}') threw unexpected exception", cT, e); } } }
@Override public void handleShutdownSignal( String consumerTag, ShutdownSignalException sig ) { if( sig.isInitiatedByApplication()) { this.logger.fine( this.sourceName + ": the connection to the messaging server was shut down." + id( consumerTag )); } else if( sig.getReference() instanceof Channel ) { int nb = ((Channel) sig.getReference()).getChannelNumber(); this.logger.fine( "A RabbitMQ consumer was shut down. Channel #" + nb + ", " + id( consumerTag )); } else { this.logger.fine( "A RabbitMQ consumer was shut down." + id( consumerTag )); } }
if (sse.isInitiatedByApplication()) { log.warn("RabbitMQ Listener of the service " + serviceName + " was disconnected, " + "Shutdown signal issued, Listner id - " + Thread.currentThread().getId()); ((ShutdownSignalException) e.getCause()).isInitiatedByApplication()) { log.warn("RabbitMQ Listener of the service " + serviceName + " was disconnected, " + "Shutdown signal issued, Listner id - " + Thread.currentThread().getId());
private static boolean isRetryable(ShutdownSignalException e) { if (e.isInitiatedByApplication()) return false; Method method = e.getReason(); if (method instanceof AMQP.Connection.Close) return isRetryable(((AMQP.Connection.Close) method).getReplyCode()); if (method instanceof AMQP.Channel.Close) return isRetryable(((AMQP.Channel.Close) method).getReplyCode()); return false; } }
private static boolean isRetryable(ShutdownSignalException e) { if (e.isInitiatedByApplication()) return false; Method method = e.getReason(); if (method instanceof AMQP.Connection.Close) return isRetryable(((AMQP.Connection.Close) method).getReplyCode()); if (method instanceof AMQP.Channel.Close) return isRetryable(((AMQP.Channel.Close) method).getReplyCode()); return false; } }