Skip to content

Create Uni off of Elastic Async, Await issues #593

Answered by Ladicek
m-dot-exe asked this question in Q&A
Discussion options

You must be logged in to vote

I'm no Elasticsearch expert, but RestHighLevelClient.updateAsync looks like a plain old callback-based API, so the easiest way to adapt that to Uni probably is:

Uni.createFrom().emitter(em -> {
    Cancellable token = restHighLevelClient.updateAsync(updateRequest, DEFAULT, new ActionListener<>() {
        void onResponse(Response response) {
            em.complete(response);
        }

        void onFailure(Exception e) {
            em.fail(e);
        }
    }
    em.onTermination(() -> token.cancel());
});

On that, you can call your .onItem().invoke(() -> someLogic())).

That said, if this is in Quarkus or Vert.x context, there's Vert.x binding for Elasticsearch high-level client (http…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@m-dot-exe
Comment options

Answer selected by m-dot-exe
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants