Skip to content

Commit

Permalink
AMQP-837: Log Exceptions thrown by ErrorHandlers
Browse files Browse the repository at this point in the history
JIRA: https://jira.spring.io/browse/AMQP-837

Also missed a comment for the last commit.

**cherry-pick to 2.0.x**
  • Loading branch information
garyrussell authored and artembilan committed Oct 19, 2018
1 parent 2c8b66e commit 969f095
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import org.aopalliance.aop.Advice;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.amqp.AmqpConnectException;
import org.springframework.amqp.AmqpIOException;
Expand Down Expand Up @@ -213,6 +214,8 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor

private boolean forceCloseChannel = true;

private String errorHandlerLoggerName = getClass().getName();

/**
* {@inheritDoc}
* @since 1.5
Expand Down Expand Up @@ -1061,6 +1064,18 @@ protected boolean isAlwaysRequeueWithTxManagerRollback() {
return this.alwaysRequeueWithTxManagerRollback;
}

/**
* Set the name (category) of the logger used to log exceptions thrown by the error handler.
* It defaults to the container's logger but can be overridden if you want it to log at a different
* level to the container. Such exceptions are logged at the ERROR level.
* @param errorHandlerLoggerName the logger name.
* @since 2.0.8
*/
public void setErrorHandlerLoggerName(String errorHandlerLoggerName) {
Assert.notNull(errorHandlerLoggerName, "'errorHandlerLoggerName' cannot be null");
this.errorHandlerLoggerName = errorHandlerLoggerName;
}

/**
* Delegates to {@link #validateConfiguration()} and {@link #initialize()}.
*/
Expand Down Expand Up @@ -1312,7 +1327,14 @@ public final boolean isRunning() {
*/
protected void invokeErrorHandler(Throwable ex) {
if (this.errorHandler != null) {
this.errorHandler.handleError(ex);
try {
this.errorHandler.handleError(ex);
}
catch (Exception e) {
LogFactory.getLog(this.errorHandlerLoggerName).error(
"Execution of Rabbit message listener failed, and the error handler threw an exception", e);
throw e;
}
}
else if (logger.isWarnEnabled()) {
logger.warn("Execution of Rabbit message listener failed, and no ErrorHandler has been set.", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ protected MessagingMessageListenerAdapter createMessageListener(MessageListenerC
}
MessageConverter messageConverter = getMessageConverter();
if (messageConverter == null) {
// fall back to the legacy converter holder in the container
messageConverter = container.getMessageConverter();
}
if (messageConverter != null) {
Expand Down

0 comments on commit 969f095

Please sign in to comment.