How to send asynchronous http request using rxjava

Does anyone know how I can write something like this where it sends an HTTPRequest asynchronously using retry logic in rxjava?

    HTTP_CLIENT.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofString())
        .thenApplyAsync(CompletableFuture::completedFuture)
        .exceptionallyAsync(throwable -> {
            CompletableFuture<HttpResponse<String>> failure = new CompletableFuture<>();
            return retrySend(httpRequest, throwable, 1, failure);
        })
        .thenComposeAsync(Function.identity())
        .thenAcceptAsync(httpResponse -> {
            errorHandler.accept(httpResponse);
        });

private CompletableFuture<HttpResponse<String>> retrySend(HttpRequest request,
        Throwable throwable, int retryCount, CompletableFuture<HttpResponse<String>> failure) {
    if (retryCount > MAX_RETRIES) {
        failure.completeExceptionally(throwable);
        return failure;
    }

    HTTP_CLIENT.sendAsync(request, HttpResponse.BodyHandlers.ofString())
        .handleAsync((httpResponse, throwable1) -> {
            if(httpResponse == null) {
                try {
                    throw new ClientException(throwable.getMessage() +
                            "Status code: 500. " + "Retry sending the message");
                } catch (Exception e) {
                    LOGGER.debug(e.getMessage(), e);
                }
                return retrySend(request, throwable1, retryCount + 1, failure);
            }
            else {
                LOGGER.debug("Successful. Status Code: " +
                        httpResponse.statusCode());
                LOGGER.debug("Body: " + httpResponse.body());
                retu rn CompletableFuture.completedFuture("Message was delivered");
            }
        });
    return failure;
}
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum