In a Spring Boot application, I have the following working code for submitting a request-response request in a Rest controller:
@GetMapping("/request-response")
public ResponseEntity<Mono<Message>> requestResponseCtr() throws InterruptedException {
Mono<Message> message = this.rsocketRequesterMono.flatMap(
requester -> requester.route("request-response")
.data(new Message(...))
.retrieveMono(Message.class)
);
log.info("\nResponse was: {}", message);
return ResponseEntity.of(Optional.of(message));
}
Based on my understanding of the RSocket Java document, I need to replace the retriveveMono(...) with send() for submitting a fire-n-forget request (on page 12 of the document). The following code should work.
@GetMapping("fire-and-forget")
public ResponseEntity<Mono<Void>> fireAndForget() throws InterruptedException {
log.info("\nFire-And-Forget...");
this.rsocketRequesterMono.flatMap(
requester -> requester.route("fire-and-forget")
.data(new Message(...))
.send()
);
return ResponseEntity.of(Optional.of(Mono.empty()));
}
It doesn't work, however. On a TCP debuting tool, there isn't any traffic for it.
What is the right way of submitting a fire-n-forget?
This call
this.rsocketRequesterMono.flatMap(
requester -> requester.route("fire-and-forget")
.data(new Message(...))
.send()
);
isn't doing anything because nothing is subscribing to it.
You likely need
ResponseEntity.of(Optional.of(this.rsocketRequesterMono.flatMap(
requester -> requester.route("fire-and-forget")
.data(new Message(...))
.send()
)));