Skip to content

Commit daa78ff

Browse files
garyrussellartembilan
authored andcommitted
Make ConditionalRejectingErrorHandler extendable
Make it easier to customize the logging behavior of the default error handler. Add protected `log()` method and make `causeChainContainsARADRE()` protected. **cherry-pick to 2.0.x, 1.7.x** https://stackoverflow.com/questions/50350377/hide-runtime-exception-in-rabbitmq-listener/50354643#50354643 (cherry picked from commit 3a6176e) # Conflicts: # spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/ConditionalRejectingErrorHandler.java
1 parent 8e0cd40 commit daa78ff

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/ConditionalRejectingErrorHandler.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2016 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -71,19 +71,33 @@ public ConditionalRejectingErrorHandler(FatalExceptionStrategy exceptionStrategy
7171

7272
@Override
7373
public void handleError(Throwable t) {
74-
if (this.logger.isWarnEnabled()) {
75-
this.logger.warn("Execution of Rabbit message listener failed.", t);
76-
}
74+
log(t);
7775
if (!this.causeChainContainsARADRE(t) && this.exceptionStrategy.isFatal(t)) {
7876
throw new AmqpRejectAndDontRequeueException("Error Handler converted exception to fatal", t);
7977
}
8078
}
8179

8280
/**
81+
* Log the throwable at WARN level, including stack trace.
82+
* Subclasses can override this behavior.
83+
* @param t the {@link Throwable}.
84+
* @since 1.7.8
85+
*/
86+
protected void log(Throwable t) {
87+
if (this.logger.isWarnEnabled()) {
88+
this.logger.warn("Execution of Rabbit message listener failed.", t);
89+
}
90+
}
91+
92+
/**
93+
* Return true if there is already an {@link AmqpRejectAndDontRequeueException}
94+
* present in the cause chain.
95+
* @param t a {@link Throwable}.
8396
* @return true if the cause chain already contains an
8497
* {@link AmqpRejectAndDontRequeueException}.
98+
* @since 1.7.8
8599
*/
86-
private boolean causeChainContainsARADRE(Throwable t) {
100+
protected boolean causeChainContainsARADRE(Throwable t) {
87101
Throwable cause = t.getCause();
88102
while (cause != null) {
89103
if (cause instanceof AmqpRejectAndDontRequeueException) {

0 commit comments

Comments
 (0)