-
Notifications
You must be signed in to change notification settings - Fork 357
Closed
Description
I wanted to limit the number of retries for resuming a connection.
I tried with this ResumeStrategy, but somehow it keeps reconnecting over and over again.
Can you help me?
public class MaxRetryResumeStrategy implements ResumeStrategy {
private final ResumeStrategy resumeStrategy;
private final AtomicLong retries;
public MaxRetryResumeStrategy(long retries, ResumeStrategy resumeStrategy) {
this.resumeStrategy = resumeStrategy;
this.retries = new AtomicLong(retries);
}
@Override
public Publisher<?> apply(ClientResume clientResume, Throwable e) {
if (this.retries.getAndDecrement() > 0) {
return Mono.from(this.resumeStrategy.apply(clientResume, e)).doOnNext(v -> System.out.println("Disconnected. Trying to resume connection..."));
}
return Mono.error(new RetryExhaustedException(e));
}
}