在 RabbitMQ 总线上使用负载较重的 spring-amqp,我们有时会从 org.springframework.amqp.rabbit.connection.CachingConnectionFactory 获取日志:
通道关闭:干净通道关闭;协议方法:#method
您能解释一下这个日志吗?为什么它处于 ERROR 级别? 我们有什么需要调整的地方吗? 预先感谢您的回答。
如果超时后未返回所有发布者确认,通道将引发异常...
@Override
public void waitForConfirmsOrDie(long timeout)
throws IOException, InterruptedException, TimeoutException
{
try {
if (!waitForConfirms(timeout)) {
close(AMQP.REPLY_SUCCESS, "NACKS RECEIVED", true, null, false);
throw new IOException("nacks received");
}
} catch (TimeoutException e) {
close(AMQP.PRECONDITION_FAILED, "TIMEOUT WAITING FOR ACK");
throw(e);
}
}
如果回复文本为
DefaultChannelCloseLogger
...,
OK
只会跳过正常关闭 (200)
/**
* Return true if the {@link ShutdownSignalException} reason is AMQP.Channel.Close and
* the reply code was AMQP.REPLY_SUCCESS (200) and the text equals "OK".
* @param sig the exception.
* @return true for a normal channel close.
*/
public static boolean isNormalChannelClose(ShutdownSignalException sig) {
Method shutdownReason = sig.getReason();
return isNormalShutdown(sig) ||
(shutdownReason instanceof AMQP.Channel.Close
&& AMQP.REPLY_SUCCESS == ((AMQP.Channel.Close) shutdownReason).getReplyCode()
&& "OK".equals(((AMQP.Channel.Close) shutdownReason).getReplyText()));
}
如果您想忽略这些错误,可以配置自定义关闭异常记录器:
/**
* Set the strategy for logging close exceptions; by default, if a channel is closed due to a failed
* passive queue declaration, it is logged at debug level. Normal channel closes (200 OK) are not
* logged. All others are logged at ERROR level (unless access is refused due to an exclusive consumer
* condition, in which case, it is logged at INFO level).
* @param closeExceptionLogger the {@link ConditionalExceptionLogger}.
* @since 1.5
*/
public void setCloseExceptionLogger(ConditionalExceptionLogger closeExceptionLogger) {
Assert.notNull(closeExceptionLogger, "'closeExceptionLogger' cannot be null");
this.closeExceptionLogger = closeExceptionLogger;
if (this.publisherConnectionFactory != null) {
this.publisherConnectionFactory.setCloseExceptionLogger(closeExceptionLogger);
}
}
关于这个问题,我们升级到RabbitMQ 3.12后也遇到了类似的问题。
RabbitMQ 3.12 - 意外的通道关闭错误,并显示 NACKS RECEIVED 消息
有什么方法可以解决问题而不是隐藏错误日志?可能会增加超时或额外的网络或rabbitmq服务器级别配置?
提前致谢 斋戒月