Method shutdownReason = shutdown.get().getReason(); assertThat(shutdownReason, instanceOf(AMQP.Connection.Close.class)); assertThat(((AMQP.Connection.Close) shutdownReason).getReplyCode(), equalTo(AMQP.CONNECTION_FORCED));
/** * Return true if there is a {@link ShutdownSignalException} in the cause tree and its * reason is "COMMAND_INVALID" and the operation being performed was exchangeDeclare. * For example attempting to declare an exchange that is not supported by the broker or * its plugins. * @param e the exception. * @return true if the exception was due to exchange declaration failed. * @since 1.6 */ public static boolean isExchangeDeclarationFailure(Exception e) { Throwable cause = e; ShutdownSignalException sig = null; while (cause != null && sig == null) { if (cause instanceof ShutdownSignalException) { sig = (ShutdownSignalException) cause; } cause = cause.getCause(); } if (sig == null) { return false; } else { Method shutdownReason = sig.getReason(); return shutdownReason instanceof AMQP.Connection.Close && AMQP.COMMAND_INVALID == ((AMQP.Connection.Close) shutdownReason).getReplyCode() && ((AMQP.Connection.Close) shutdownReason).getClassId() == EXCHANGE_CLASS_ID_40 && ((AMQP.Connection.Close) shutdownReason).getMethodId() == DECLARE_METHOD_ID_10; } }
/** * Return true if the {@link ShutdownSignalException} reason is AMQP.Connection.Close and * the reply code was AMQP.REPLY_SUCCESS (200) and the text equals "OK". * @param sig the exception. * @return true for a normal connection close. */ public static boolean isNormalShutdown(ShutdownSignalException sig) { Method shutdownReason = sig.getReason(); return shutdownReason instanceof AMQP.Connection.Close && AMQP.REPLY_SUCCESS == ((AMQP.Connection.Close) shutdownReason).getReplyCode() && "OK".equals(((AMQP.Connection.Close) shutdownReason).getReplyText()); }
/** * Return true if there is a {@link ShutdownSignalException} in the cause tree and its * reason is "COMMAND_INVALID" and the operation being performed was exchangeDeclare. * For example attempting to declare an exchange that is not supported by the broker or * its plugins. * @param e the exception. * @return true if the exception was due to exchange declaration failed. * @since 1.6 */ public static boolean isExchangeDeclarationFailure(Exception e) { Throwable cause = e; ShutdownSignalException sig = null; while (cause != null && sig == null) { if (cause instanceof ShutdownSignalException) { sig = (ShutdownSignalException) cause; } cause = cause.getCause(); } if (sig == null) { return false; } else { Method shutdownReason = sig.getReason(); return shutdownReason instanceof AMQP.Connection.Close && AMQP.COMMAND_INVALID == ((AMQP.Connection.Close) shutdownReason).getReplyCode() && ((AMQP.Connection.Close) shutdownReason).getClassId() == EXCHANGE_CLASS_ID_40 && ((AMQP.Connection.Close) shutdownReason).getMethodId() == DECLARE_METHOD_ID_10; } }
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; } }
/** * Return true if the {@link ShutdownSignalException} reason is AMQP.Connection.Close and * the reply code was AMQP.REPLY_SUCCESS (200) and the text equals "OK". * @param sig the exception. * @return true for a normal connection close. */ public static boolean isNormalShutdown(ShutdownSignalException sig) { Method shutdownReason = sig.getReason(); return shutdownReason instanceof AMQP.Connection.Close && AMQP.REPLY_SUCCESS == ((AMQP.Connection.Close) shutdownReason).getReplyCode() && "OK".equals(((AMQP.Connection.Close) shutdownReason).getReplyText()); }
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; } }