Creating a RSocket Client
Explore how to create a reactive RSocket client in Spring Boot by building a WebFlux controller that forwards HTTP requests over an RSocket connection. Understand the use of RSocketRequester, Mono for lazy connection handling, and setup configurations including TCP connection and retry logic. This lesson helps you implement efficient client-side communication using RSocket and Reactor in Spring Boot.
We'll cover the following...
Configuring a client-side REST controller
Let’s create a WebFlux controller that will take incoming HTTP requests and forward them to the back-end server over its RSocket connection. That’s perhaps not as sophisticated as, say, a template that uses WebSockets to communicate from the browser to the backend. That said, learning how RSockets work makes for an effective example.
We’ll do this by creating a class called RSocketController in our newly-minted rsocket-client application in the com.greglturnquist.hackingspringboot package as follows:
-
In line 1,
@RestControllersignals that this class is used for an API not rendering HTML. -
In line 3,
Mono<RSocketRequestor>is a Reactor wrapper around Spring Framework’s ...