Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Simultaneous Reactive WebClient Requests #101

Open
dvas0004 opened this issue Sep 25, 2019 · 0 comments
Open

Spring Simultaneous Reactive WebClient Requests #101

dvas0004 opened this issue Sep 25, 2019 · 0 comments
Assignees

Comments

@dvas0004
Copy link
Owner

The Spring WebClient is a reactive webclient. In general the workflow with webclient is (in kotlin):

val webClient = WebClient.create("http://x.y.z.")
          .post()
          .uri("/events*/_search")
          .contentType(MediaType.APPLICATION_JSON)
          .accept(MediaType.APPLICATION_JSON)
          .body(BodyInserters.fromObject(someJSON))
          .exchange()
          .flatMap { clientResponse -> clientResponse.bodyToMono(String::class.java) }

In the above case, webClient will be a Mono<String>, which hasn't been executed yet (since there's no subscription). We can gather multiple such "webclients" into an array, and execute all simultaneously by using Flux.merge, for example:

val webClients = ArrayList<Mono<String>>()
webClients.add(webClient) // usually called multiple times

Flux.merge( webClients ).subscribe{ e -> println(e) } //web calls done simultaneously here
@dvas0004 dvas0004 self-assigned this Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant