retry on Single not getting hit on server

24 views Asked by At
return Single.fromFuture(
        asyncStub.withDeadlineAfter(ClientConfiguration.INSTANCE.getMaxTimeout(), TimeUnit.SECONDS).checkBalance(payload))
        .doOnSubscribe(s -> System.out.println("subscribing"))
        .doOnSuccess((resp) -> {
                    log.info("Check Balance got response success {}", resp.getUserID());
                    log.debug("Check Balance got response success {}", resp.toString());
                })
        .doOnError(throwable -> {
                    this.logError(throwable, "Check balance userid:" + payload);
                })
        .retry((retryCount, error) -> retryCount < 3).toFuture();

From client its getting retried but on server its not getting new request Please suggest what I'm doing wrong

1

There are 1 answers

0
akarnokd On

Apparently you create a Future before RxJava is involved thus retrying a "constant" has no effect. I.e.,

var serverCall = asyncStub.withDeadlineAfter(
        ClientConfiguration.INSTANCE.getMaxTimeout(), TimeUnit.SECONDS
    )
    .checkBalance(payload)
;

Single.fromFuture(serverCall)

You have to make the creation of a fresh Future happen when a (re)subscription happens:

return Single.defer(() -> 
    Single.fromFuture(
        asyncStub.withDeadlineAfter(
            ClientConfiguration.INSTANCE.getMaxTimeout(), TimeUnit.SECONDS
        )
        .checkBalance(payload)
    )
)
.doOnSubscribe(s -> System.out.println("subscribing"))
.doOnSuccess((resp) -> {
                    log.info("Check Balance got response success {}", resp.getUserID());
                    log.debug("Check Balance got response success {}", resp.toString());
})
.doOnError(throwable -> {
                    this.logError(throwable, "Check balance userid:" + payload);
})
.retry((retryCount, error) -> retryCount < 3)
.toFuture()