Search⌘ K
AI Features

Converting a Webflux Request Into an RSocket Channel

Explore how to convert WebFlux requests into RSocket channels, enabling bidirectional streaming between client and server. Understand server setup, event monitoring, and how to handle reactive streams using Spring Boot and WebFlux.

We'll cover the following...

Listening for new events

Having covered the two paradigms RSocket offers for 1-to-1 send-receive, we can now move into the really cool stuff. Namely, RSocket’s support for a bidirectional channel.

The following example sends a single message to subscribe to a flow of events:

Java
@GetMapping(value = "/items", produces = TEXT_EVENT_STREAM_VALUE) //1
Flux<Item> liveUpdates() {
return this.requester
.flatMapMany(rSocketRequester -> rSocketRequester
.route("newItems.monitor") //2
.retrieveFlux(Item.class)); //3
}
Listening for new events over an RSocket using a channel

Here’s a breakdown of the code above:

  1. In line 1, @GetMapping denotes that this method is used to receive traffic, not alter the system. The TEXT_EVENT_STREAM_VALUE declares that we want to stream the results as they occur and is supported by tools such as cURL.

  2. In ...