Reactive Programming with RSocket and Spring Boot

In this article, we’ll explore the RSocket protocol and its use with Spring Boot

Somnath Musib

--

RSocket is an application protocol for multiplexed, duplex communication over TCP, WebSocket, and other byte stream transports such as Aeron. RSocket allows the following four communication models as shown in following figure 1:

Figure 1 Communication models in RSocket protocol. In the Fire-and-Forget pattern, a client sends one message and expect no response from the server. In the Request-Response pattern, the client sends one message and receives one back from the server. In the Request-Stream pattern, a client sends one message and expects a stream of messages in response from the server. In the Channel pattern, the client and server send streams of messages to each other

In RSocket, once the initial handshake between the client and server is done, the “client” vs “server” distinction is lost as both sides can independently initiate one of the interactions as specified in figure 1.

The RSocket protocol has few key features and offers several benefits:

  • Reactive Streams semantics for streaming requests interactions Request-Stream and Channel. Support for backpressure signal between requester and responder. This allows a requester to slow down a responder at the source. Thus, reduces reliance on network layer congestion control and network-level buffering
  • Support for Request throttling to reduce the number of possible messages. This can be done after sending a LEASE frame to limit the total number of requests allowed by other ends for a given time
  • Fragmentation and re-assembly of large messages
  • Keepalive through heartbeat…

--

--

Somnath Musib

4X AWS | Staff Software Engineer, Cloud Architect | Author "Spring Boot In Practice" | Find more at https://musibs.github.io