Skip to content

Commit bb45fb4

Browse files
committed
Restore sleep interval between recovery attempt
Commit 6a04831 introduced a regression that lead to burst recovery attempts when the broker is up but the listener is failing for some reason (the most obvious one being that the destination does not exist). Since the sleep period between recovery attempts strategy is more complex, we can't just sleep for a period of time. But we can create an execution and apply it once which should work just fine for most use cases. Issue: SPR-12183
1 parent a6c2d45 commit bb45fb4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,11 @@ public void run() {
10401040
}
10411041
catch (Throwable ex) {
10421042
clearResources();
1043+
if (!this.lastMessageSucceeded) {
1044+
// We failed more than once in a row or on startup - sleep before
1045+
// first recovery attempt.
1046+
sleepBeforeRecoveryAttempt();
1047+
}
10431048
this.lastMessageSucceeded = false;
10441049
boolean alreadyRecovered = false;
10451050
synchronized (recoveryMonitor) {
@@ -1191,6 +1196,17 @@ private void clearResources() {
11911196
this.session = null;
11921197
}
11931198

1199+
/**
1200+
* Apply the back off time once. In a regular scenario, the back off is only applied if we
1201+
* failed to recover with the broker. This additional sleep period avoids a burst retry
1202+
* scenario when the broker is actually up but something else if failing (i.e. listener
1203+
* specific).
1204+
*/
1205+
private void sleepBeforeRecoveryAttempt() {
1206+
BackOffExecution execution = DefaultMessageListenerContainer.this.backOff.start();
1207+
applyBackOffTime(execution);
1208+
}
1209+
11941210
@Override
11951211
public boolean isLongLived() {
11961212
return (maxMessagesPerTask < 0);

0 commit comments

Comments
 (0)