Learning RSocket
Using RSC
September 1–2, 2021
springone.io
Toshiaki Maki (@making)
Staff Cloud Native Architect at VMware
https://github.com/making/learning-rsocket-using-rsc
1
What is RSocket?
● RSocket is a binary protocol for multiplexed, bidirectional over TCP or
WebSocket
○ https://rsocket.io
○ Layer 5 or 6 in the OSI model / Application layer in the TCP/IP model
● 4 interaction models
○ Request Response
○ Request Stream
○ Request Channel
○ Fire and Forget
● Support Reactive Streams semantics (Backpressure)
● A Reactive Foundation project
○ https://www.reactive.foundation
2
FAQ: What’s different from gRPC?
3
Transport Agnostic
(TCP / WebSocket / …)
RSocket Protocol
Message Format Agnostic
(JSON / CBOR / Protocol Buffers / ...)
Programming Model Agnostic
(Messaging / RPC / Functional Style)
Language Agnostic
(Java / Kotlin / JavaScript / Swift / ...)
HTTP/2
Protocol Buffers
RPC Style
Language Agnostic
(Go / C++ / Java / Python / C# / ...)
Transport
Message
Format
Programming
Model
Language
Spring ❤ RSocket
Spring Framework provides a “Messaging Style” and “Functional Style”
programming model for RSocket
And a convenient RSocket Client like WebClient for Spring WebFlux
https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#rsocket
4
@Controller
public class UpperCase {
@MessageMapping("uc")
String uc(@Payload String s) {
return s.toUpperCase();
}
}
RSocketRequester requester =
RSocketRequester.builder()
.tcp("localhost", 7000);
Mono<String> response =
requester.route("uc")
.data("Hello")
.retrieveMono(String.class);
Server Client
What is RSC?
RSC is a CLI for RSocket like curl for HTTP.
https://github.com/making/rsc
Uses RSocket Java SDK and built with GraalVM into a native image.
Available for Mac, Linux and Windows.
Very convenient for testing RSocket Server API.
5
$ brew install making/tap/rsc
$ rsc --route=uc --data=Hello tcp://localhost:7000
HELLO
4 Interaction Models
● Request Response … send one message and receive one back
● Request Stream …  send one message and receive a stream of messages
● Request Channel … send streams of messages in both directions
● Fire and Forget … send a one-way message
6
Request Response
Request Response
Payload
Payload
send one message and receive one back
7
Request Stream
Request Stream
Payload
Payload
Payload Payload …
Payload
send one message and receive a stream of messages back
8
Request Channel
Request Channel
Payload
Payload
Payload Payload …
Payload
Payload
…
send streams of messages in both directions
9
Fire and Forget
Fire and Forget
Payload
send a one-way message
10
DEMO: 4 interaction models
11
RSocket Features Demo
● Reactive Streams (Back Pressure)
● Session Resumption
● Client Responder
● Authentication
● Tracing
12
Reactive Streams (Back Pressure support)
Request_N
N=3
Payload
Payload
Payload
Request_N
N=2
Payload
Payload
...
...
13
Demo: Reactive Streams (Back Pressure support)
14
Session Resumption
Request Stream
E
D
C
B
A ...
Connectivity Lost
15
Session Resumption
Resume
G
F
E
D
C ...
Backpressure works, so stream data generation
will stop until the connection is resumed.
16
DEMO: Session Resumption
RSocket Server
RSC
socat
Listens on port 7000
rsc --route ... --stream --resume 180 
--delayElements 1000 --limitRate 1 
tcp://localhost:7002
socat -d TCP-LISTEN:7002,fork,reuseaddr TCP:localhost:7000
17
Port
7002
Port
7000
DEMO: Session Resumption
18
Client Responder
Request Response
Payload
Payload
Responder
Requester
Client Server
19
Client Responder
Request Response
Payload
Payload
Requester
Responder
Client Server
Server can be a Requester!
2
0
Firewall
Client Responder
Request Response
Payload
Payload
Requester
Responder
Client Server
21
✅ Allow
❌ Deny
✅
✅
inside outside
DEMO: Client Responder
2
2
REQUEST: SpringOne
RESPONSE: Hello SpringOne!
Responder
Client
Requester
Server
Server initiates
a request response flow
DEMO: Client Responder
2
3
Authentication
RSocket protocol supports Simple Authentication ( username / password ) and
Bearer Token Authentication
https://github.com/rsocket/rsocket/blob/master/Extensions/Security/Authentication.md
Spring Security supports RSocket Authentication
2
4
DEMO: Authentication
2
5
Tracing
RSocket protocol supports Zipkin Tracing (B3 Format).
https://github.com/rsocket/rsocket/blob/master/Extensions/Tracing-Zipkin.md
Spring Cloud Sleuth ( since 3.1 🆕 ) provides an instrumentation for RSocket Tracing.
2
6
DEMO: Tracing
27
Wrap up
● RSocket is a binary protocol for multiplexed, bidirectional over TCP or WebSocket
● Spring ❤ RSocket
● RSC is a CLI for RSocket like curl for HTTP.
● 4 interaction models
○ Request Response
○ Request Stream
○ Request Channel
○ Fire and Forget
● Highlighted features
○ Backpressure
○ Session Resumption
○ Client Responder
○ Authentication
○ Tracing
2
8
https://github.com/making/learning-rsocket-using-rsc
Event Sourcing with RSocket—Now We’re Talking! - Steven van Beelen
Collaborative Applications at Scale with RSocket - Sergey Tselovalnikov
Multiplatform Apps with Spring, Kotlin, and RSocket - Anton Arhipov, Oleh Dokuka
#springone
@SpringOne
Stay Connected.

Learning RSocket Using RSC