How to integrate Spring Retry with AsyncRestTemplate

Viewed 1971

How can you integrate Spring Retry with external calls with AsyncRestTemplate? If it's not possible, is there another framework that supports it?

My use case:

public void doSomething() throws ExecutionException, InterruptedException {

    ListenableFuture<ResponseEntity<String>> future = asyncRestTemplate.getForEntity("http://localhost/foo", String.class);

    // do some tasks here

    ResponseEntity<String> stringResponseEntity = future.get(); // <-- How do you retry just this call?

}

How do you retry this future.get() call? If the external service returns a 404, I want to avoid calling those tasks in between again and just retry the external call? I can't just wrap future.get() with a retryTemplate.execute() because it won't actually make another call to the external service.

1 Answers
Related