Using Retry class from reactor-extra

40 views
Skip to first unread message

Par Asm

unread,
Aug 27, 2018, 8:52:19 PM8/27/18
to reactor-framework
Hi,

I have the following code:
Mono mo = Mono.fromFuture(makeCompletableFuture(amazonDynamoDBAsync.getItemAsync(myGetRequest)));

The private method is as follows. Basically it restricts the Dynamo get operation to max of 1ms.

private static <T> CompletableFuture<T> makeCompletableFuture(@NonNull Future<T> future) {
System.out.println("Retrying ....");
return CompletableFuture.supplyAsync(() -> {
try {
return future.get(1,TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
}
});
}

In 99% of the cases, this code works. But sometimes the network latencies cause the get operation to exceed 1ms. I do not want to increase the Future.get() timeout to higher value. Rather I want to make this method retry if the Dynamo get does not complete within 1ms.
So I made the below change to use Retry from io.projectreactor.addons:reactor-extra::3.1.6.RELEASE

Retry retry = Retry.anyOf(CompletionException.class, RuntimeException.class, TimeoutException.class)
.timeout(Duration.ofMillis(10))
.retryMax(10);

Mono mo = Mono.fromFuture(makeCompletableFuture(amazonDynamoDBAsync.getItemAsync(myGetRequest)));
return mo.retryWhen(retry);

However, I do not see the Dynamo get operation being retried even if the get operation fails to complete in 1ms on Dynamo. 
What is wrong here?

Thanks for your help.

Par Asm

unread,
Aug 28, 2018, 8:22:22 PM8/28/18
to reactor-framework
I was able to solve this issue using Mono.defer()
Reply all
Reply to author
Forward
0 new messages