Skip to content

Commit 914c6f8

Browse files
garyrussellartembilan
authored andcommitted
GH-1429: Improve ConditionalRejectingErrorHandler
Resolves #1249 Add protected getters for private fields; add `handleDiscarded()`.
1 parent f6ebba8 commit 914c6f8

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ public ConditionalRejectingErrorHandler(FatalExceptionStrategy exceptionStrategy
7777
this.exceptionStrategy = exceptionStrategy;
7878
}
7979

80+
/**
81+
* Return the discardFatalsWithXDeath.
82+
* @return the discardFatalsWithXDeath.
83+
* @since 2.3
84+
* @see #setDiscardFatalsWithXDeath(boolean)
85+
*/
86+
protected boolean isDiscardFatalsWithXDeath() {
87+
return this.discardFatalsWithXDeath;
88+
}
89+
8090
/**
8191
* Set to false to disable the (now) default behavior of logging and discarding
8292
* messages that cause fatal exceptions and have an `x-death` header; which
@@ -89,6 +99,16 @@ public void setDiscardFatalsWithXDeath(boolean discardFatalsWithXDeath) {
8999
this.discardFatalsWithXDeath = discardFatalsWithXDeath;
90100
}
91101

102+
/**
103+
* Return the rejectManual.
104+
* @return the rejectManual.
105+
* @since 2.3
106+
* @see #setRejectManual(boolean)
107+
*/
108+
protected boolean isRejectManual() {
109+
return this.rejectManual;
110+
}
111+
92112
/**
93113
* Set to false to NOT reject a fatal message when MANUAL ack mode is being used.
94114
* @param rejectManual false to leave the message in an unack'd state.
@@ -98,6 +118,15 @@ public void setRejectManual(boolean rejectManual) {
98118
this.rejectManual = rejectManual;
99119
}
100120

121+
/**
122+
* Return the exception strategy.
123+
* @return the strategy.
124+
* @since 2.3
125+
*/
126+
protected FatalExceptionStrategy getExceptionStrategy() {
127+
return this.exceptionStrategy;
128+
}
129+
101130
@Override
102131
public void handleError(Throwable t) {
103132
log(t);
@@ -109,6 +138,7 @@ public void handleError(Throwable t) {
109138
if (xDeath != null && xDeath.size() > 0) {
110139
this.logger.error("x-death header detected on a message with a fatal exception; "
111140
+ "perhaps requeued from a DLQ? - discarding: " + failed);
141+
handleDiscarded(failed);
112142
throw new ImmediateAcknowledgeAmqpException("Fatal and x-death present");
113143
}
114144
}
@@ -118,6 +148,16 @@ public void handleError(Throwable t) {
118148
}
119149
}
120150

151+
/**
152+
* Called when a message with a fatal exception has an {@code x-death} header, prior
153+
* to discarding the message. Subclasses can override this method to perform some
154+
* action, such as sending the message to a parking queue.
155+
* @param failed the failed message.
156+
* @since 2.3
157+
*/
158+
protected void handleDiscarded(Message failed) {
159+
}
160+
121161
/**
122162
* Log the throwable at WARN level, including stack trace.
123163
* Subclasses can override this behavior.

0 commit comments

Comments
 (0)