Consider a code:
private WebClient webClient;
public void some(MyObject myObject) {
return webClient.post()
.uri("/log/my-path")
.body(BodyInserters.fromObject(myObject))
.retrieve()
.bodyToMono(Void.class)
.subscribeOn(Schedulers.single());
}
This code "waits" when response "appears" and then completes. (E.g. retrieve()
is called). but how not to wait for response? For example, I make request and return Mono.empty
without waiting for response. How to do that?
P.S. A technique when request is sent without wating for response is called "fire and forget".
UPDATED
- Any mono functions like
then
does not work. Because they invocated afterbodyToMono
which "waits" until http response is comming. E.g. nothing (event async) is called untilbodyToMono
completes. - "remove"
return
statment also does not work. May be in somemain
functions it works but not in Spring application. This does not wok becauseMono
just created in that case, but nobody run it. AnyMono
methods likemap, flatMap
etc. is just funciton "setting" but not Mono running.
remove the 'return' statement and and it will be fire in the background.
No, mono will not be run at all in that case.