...
/Converting a Webflux Request Into an RSocket Request/Response
Converting a Webflux Request Into an RSocket Request/Response
Learn how to forward a new item over RSocket and create a test class using the autoconfigured WebTestClient.
Forwarding Item
using request/response
Check out the code below to see how we can connect an incoming HTTP POST
with WebFlux to our RSocket request/response method on the server.
@PostMapping("/items/request-response") //1Mono<ResponseEntity<?>> addNewItemUsingRSocketRequestResponse(@RequestBody Item item) {return this.requester.flatMap(rSocketRequester -> rSocketRequester.route("newItems.request-response") //2.data(item) //3.retrieveMono(Item.class)) //4.map(savedItem -> ResponseEntity.created( //5URI.create("/items/request-response")).body(savedItem));}
Forwarding a new Item over an RSocket using request/response
Here’s a breakdown of the code above:
-
In line 1,
@PostMapping(...)
indicates that this Spring WebFlux method acceptsHTTP POST
requests at the/items/request-response
route. -
In line 5, we can
route()
this request to the destinationnewItems.request-response
by flat mapping over theMono<RSocketRequestor>
. -
In line 6, we submit the payload of the
Item
object in thedata()
method. -
In line 7, we ...