Skip to content

Commit a0ccd99

Browse files
vikinghawkacogoluegnes
authored andcommitted
tweaks to recovery retry helper
(cherry picked from commit 9b5adbe) Conflicts: src/main/java/com/rabbitmq/client/impl/recovery/TopologyRecoveryRetryLogic.java
1 parent c764cdc commit a0ccd99

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/main/java/com/rabbitmq/client/impl/recovery/DefaultRetryHandler.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ public RetryResult retryConsumerRecovery(RetryContext context) throws Exception
9696

9797
protected <T extends RecordedEntity> RetryResult doRetry(RetryCondition<T> condition, RetryOperation<?> operation, T entity, RetryContext context)
9898
throws Exception {
99-
log(entity, context.exception());
10099
int attempts = 0;
101100
Exception exception = context.exception();
102101
while (attempts < retryAttempts) {
103102
if (condition.test(entity, exception)) {
103+
log(entity, context.exception(), attempts);
104104
backoffPolicy.backoff(attempts + 1);
105105
try {
106106
Object result = operation.call(context);
@@ -115,11 +115,11 @@ protected <T extends RecordedEntity> RetryResult doRetry(RetryCondition<T> condi
115115
throw exception;
116116
}
117117
}
118-
throw context.exception();
118+
throw exception;
119119
}
120120

121-
protected void log(RecordedEntity entity, Exception exception) {
122-
LOGGER.info("Error while recovering {}, retrying with {} attempt(s).", entity, retryAttempts, exception);
121+
protected void log(RecordedEntity entity, Exception exception, int attempts) {
122+
LOGGER.info("Error while recovering {}, retrying with {} more attempt(s).", entity, retryAttempts - attempts, exception);
123123
}
124124

125125
public static abstract class RetryOperation<T> {

src/main/java/com/rabbitmq/client/impl/recovery/TopologyRecoveryRetryLogic.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.rabbitmq.client.AMQP;
1919
import com.rabbitmq.client.ShutdownSignalException;
20+
import com.rabbitmq.utility.Utility;
2021

2122
import static com.rabbitmq.client.impl.recovery.TopologyRecoveryRetryHandlerBuilder.builder;
2223

@@ -136,7 +137,7 @@ public String call(RetryContext context) throws Exception {
136137
public Void call(RetryContext context) throws Exception {
137138
if (context.entity() instanceof RecordedConsumer) {
138139
String queue = context.consumer().getQueue();
139-
for (RecordedBinding recordedBinding : context.connection().getRecordedBindings()) {
140+
for (RecordedBinding recordedBinding : Utility.copy(context.connection().getRecordedBindings())) {
140141
if (recordedBinding instanceof RecordedQueueBinding && queue.equals(recordedBinding.getDestination())) {
141142
recordedBinding.recover();
142143
}
@@ -147,16 +148,15 @@ public Void call(RetryContext context) throws Exception {
147148
};
148149

149150
/**
150-
* Pre-configured {@link DefaultRetryHandler} that retries recovery of bindings and consumers
151+
* Pre-configured {@link TopologyRecoveryRetryHandlerBuilder} that retries recovery of bindings and consumers
151152
* when their respective queue is not found.
152153
* This retry handler can be useful for long recovery processes, whereby auto-delete queues
153154
* can be deleted between queue recovery and binding/consumer recovery.
154155
*/
155-
public static final RetryHandler RETRY_ON_QUEUE_NOT_FOUND_RETRY_HANDLER = builder()
156+
public static final TopologyRecoveryRetryHandlerBuilder RETRY_ON_QUEUE_NOT_FOUND_RETRY_HANDLER = builder()
156157
.bindingRecoveryRetryCondition(CHANNEL_CLOSED_NOT_FOUND)
157158
.consumerRecoveryRetryCondition(CHANNEL_CLOSED_NOT_FOUND)
158159
.bindingRecoveryRetryOperation(RECOVER_CHANNEL.andThen(RECOVER_BINDING_QUEUE).andThen(RECOVER_BINDING))
159160
.consumerRecoveryRetryOperation(RECOVER_CHANNEL.andThen(RECOVER_CONSUMER_QUEUE.andThen(RECOVER_CONSUMER)
160-
.andThen(RECOVER_CONSUMER_QUEUE_BINDINGS)))
161-
.build();
161+
.andThen(RECOVER_CONSUMER_QUEUE_BINDINGS)));
162162
}

src/test/java/com/rabbitmq/client/test/functional/TopologyRecoveryRetry.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void topologyRecoveryRetry() throws Exception {
5555
@Override
5656
protected ConnectionFactory newConnectionFactory() {
5757
ConnectionFactory connectionFactory = TestUtils.connectionFactory();
58-
connectionFactory.setTopologyRecoveryRetryHandler(RETRY_ON_QUEUE_NOT_FOUND_RETRY_HANDLER);
58+
connectionFactory.setTopologyRecoveryRetryHandler(RETRY_ON_QUEUE_NOT_FOUND_RETRY_HANDLER.build());
5959
connectionFactory.setNetworkRecoveryInterval(1000);
6060
return connectionFactory;
6161
}

0 commit comments

Comments
 (0)