
Explore why rSocket solves microservices challenges by enabling persistent TCP connections, binary messages, non-blocking streaming, and server push, enhancing inter-service communication beyond HTTP.
This demo compares rest over http with rsocket for a square-aggregation task, using request-response and request-channel (bidirectional streaming) models, showing rsocket’s faster averages and higher throughput.
Familiarize yourself with sockets without spring boot, establishing a persistent TCP connection where any side can be a requester or responder, with reactive streams, back pressure, and WebSocket transport.
Discover RSocket interaction models, including request and response, fire and forget, request streaming, and bidirectional request channel, with guaranteed message order.
Set up a maven rSocket project in an empty directory, choose java 8–11, add circuit and socket transport dependencies with jackson data bind, and import junit and project reactor.
Create a simple RSocket service and override fire-and-forget payload handling to read data as UTF-8 from the byte buffer and print the received payload.
Expose the fire-and-forget api by implementing a socket acceptor that returns the math service as the socket, and start an rSocket server on port 6565 to keep listening.
Create an RSocket client in a test to send a fire-and-forget request to the server running on localhost:6565, using tcp client transport and RSocket connector.
Explore invoking fire and forget in rSocket, sending a payload that completes without a response, requiring subscription to trigger execution, and showing the client succeeds as remote socket processes message.
Watch how a socket acceptor handles a new connection as the server starts and listens on port 6565, with fire-and-forget calls observed three times.
Learn rsocket fire and forget, where a client sends a request without waiting for a response, even with a five-second server delay, unlike web flex.
Develop a Java utility to serialize and deserialize objects to and from byte payloads using Jackson's ObjectMapper, enabling real objects to be sent over rSocket requests and responses.
Create data transfer objects, including a request DTO and a response DTO, with getters, setters, and constructors, and test with object util payloads in Spring rSocket microservices.
Implement the request-response flow for a math service: read the input payload, compute the square, create a response DTO, and return it via a mono payload.
Explain how request stream delivers a sequence of server responses to a single client payload using a multiplication table example with real time emission and cancellation.
Explain the request channel as bidirectional streaming, where a client sends numbers and a server returns results, demonstrated by plotting a console graph of y = x^2 + 1.
Explore RSocket interaction models through real time examples, including request/response, fire-and-forget, request stream, and request channel, with practical cases from user creation, order updates, and live bidirectional chat.
Explore peer to peer messaging with rSocket by implementing server and client socket roles, configuring a socket acceptor, and enabling request response, fire and forget, and request stream interactions.
Implement a batch job service for peer-to-peer messaging using fire-and-forget over sockets. The server computes the cube of the input asynchronously and later returns a response.
Implement a fire-and-forget rSocket client with a callback service, wiring a socket acceptor to receive server callbacks and verify behavior in a callback test.
Explore back pressure in a reactive publisher-subscriber setup, where a fast server stream of 1000 items adjusts to a slow client, revealing a default 32-item queue.
Demonstrates how a persistent client–server connection via a socket can break when the server restarts, producing a 'closed channel exception,' and explores how to fix this.
Examine the persistent connection problem and implement a robust fix by switching to a socket client that uses a mono payload, enabling automatic reconnect after server restarts.
Configure the RSocket socket acceptor to use the connection setup payload for credential-based access, granting the math service or a free service with a three-item stream limit.
Demonstrates establishing an RSocket connection using a setup payload, sending a request payload to a math service, and validating credentials with ten items and a complete signal.
Explore binary socket concepts for microservices, including reactive, non-blocking communication with back pressure over TCP and web sockets, API models: request and response, fire and forget, request stream, request channel.
Discover how Spring rsocket autoconfigures, serialization and deserialization, and dependency injection with routing to support request response, fire and forget, request stream, and request channel models.
Redo the same math service using Spring rsocket to compare with socket, implementing computation request and response DTOs via controller and service layer, with getters, setters, toString, and no-arg constructors.
Define a math service in the service layer using mono and flux, implementing fire and forget and request–response patterns, mapping inputs to square outputs and streaming chart via request channel.
Implement a message-mapped spring rSocket controller wiring a math service to endpoints like print and find square, with table and chart streams using mono and flux.
Learn to build and configure a Spring RSocket client using the RSocketRequester builder, then perform a fire-and-forget call to the print endpoint with computation input.
Explore RSocket interaction models with Spring, including request-response, request stream, and request channel, by implementing computation requests, mono and flex types, and chart streaming.
Explore how to access a path variable as a destination variable in a spring rest controller, wiring a map variable controller, and testing via a reactive mono endpoint.
Explore how Spring infers RSocket interaction types from input and output, selecting request response or request stream, even with empty input for routes like product dot all.
Validate input on a spring rsocket endpoint by doubling numbers up to 30 and returning an error for larger inputs, while illustrating server-side validation and application error handling.
Learn how reactive rSocket handles application errors without exposing exception details, using onErrorReturn, onErrorContinue, or switchIfEmpty to emit defaults or items.
Implement a message exception handler in the rSocket microservice to emit a default value minus one when validation fails; note controller advice is not working yet for socket.
Explore creating a generic response wrapper that carries an error event with a status code or a success payload, and expose factory methods to produce each path.
Enable the server to call the client for a batch job using spring boot and a socket requester, handling fire-and-forget submissions and returning results via the batch job response endpoint.
Develop the Spring RSocket client side by creating a batch job response controller with an exposed endpoint, enabling fire-and-forget or request-response callbacks via Mono when the server calls back.
Explore a client–server number guessing game over rSocket using request channel, where the client narrows a 1–100 range with server-driven feedback to optimize guesses.
Implement a server-side rSocket game in Spring, using a reactive Flux to compare client guesses with a random server number and return greater, lesser, or equal feedback.
Implement a client-side binary search game, where a player class emits mid-value guesses within a lower and upper bound, and updates bounds based on the server's responses while logging attempts.
Programmatically emit multiple integers as a unicast flux with a buffer backpressure strategy, exposing a flux of guesses and consuming guess number responses to drive the game.
Experience a live demo of client versus server communication, sending numbers and receiving equal, lesser, or greater responses, in a high-performance microservices context.
Explore how Spring handles RSocket connection setup using a connect mapping and a dedicated controller. The connection setup runs once, then subsequent requests can be sent over the same connection.
learn how to pass a client connection request with an id and secret key during rSocket connection setup, and validate credentials on the server to accept or reject the setup.
Learn to dispose and close rSocket connections in Spring Boot, handle socket requests, and close the channel or reject the connection when the password is wrong.
Create a thread-safe connection manager that tracks socket requesters in a synchronized set, adds on connect, removes on close, and periodically prints current connections, wired into the connection handler.
Create a two-client setup with a connection manager in spring rsocket, forcing lazy connections via two requesters, then enable server mode and a client-manager notify flow for product updates.
Configure multiple connect mappings to route math event updates only to interested clients, using setup data and setup route, with only one connection stored.
Explain how Kinect mapping behaves with single and implicit mapping with no route, showing that any client may connect via an implicit route and how to override with custom logic.
Learn how to configure rSocket connector retries with a retry strategy, delay, and max attempts, handle server downtime, reestablish connections, and resume from where it left off without discarding requests.
Explore session resumption in R socket by handling network interruptions during bidirectional streaming. Learn how retry strategies and a proxy setup with Nginx help restore the session after connectivity loss.
Session resumption part 2 demonstrates modifying the map controller to emit 1000 values on a table stream with a 1-second delay, enabling nginx testing and a quick session resumption test.
Set up nginx across Windows, Mac, and Docker by installing and backing up nginx.conf, switch to stream for TCP, and forward port 6566 to 6565 socket servers.
Implement a resume strategy to handle streaming responses when nginx goes down, using a fixed-delay retry and reconnect approach for new requests.
Enable session resumption for streaming with a dedicated server config and client resume strategy, including a five-minute session, fixed-delay retries, and seamless recovery after network disruption.
Explore connection setup and connect mapping options, including setup routes and implicit mappings, with retry resume and handling server restarts via reconnect and streaming resume.
Explore load balancing with persistent connections, showing how proxies route requests to backend instances and why connections may stick to one machine until restart.
Package the application and run multiple backend instances, print logs to track connect mapping and which instance handles requests, and use fire-and-forget print messages to observe port-based execution.
This lecture demonstrates configuring Nginx as a load balancer for three backends (ports 7070, 7071, 7072) and explains how connections are balanced while established ones stay with a single backend.
Explore client side load balancing in microservices by using a service registry to discover multiple payment service instances, compare it with server side balancing, and outline pros and cons.
Create a fake service registry for client side load balancing with a Spring registry client, exposing socket server instances (localhost:7070, 7071, 7072) retrievable by service name.
Develop a configuration package and a load balance target config class that converts service registry instances into load balance targets using a reactive mono of targets and a client transport.
Create a client side load balancing test using a round robin strategy, a socket requester, and flux interval to periodically emit updated targets from the registry service.
Demonstrates client-side load balancing under instance failure, showing tests where an instance dies and requests are rerouted to remaining targets, preserving balanced load.
Weighted load balancing uses latency-based weights to steer requests toward faster instances rather than round-robin, helping cloud deployments across multiple availability zones.
Explore server side and client side load balancing, comparing ease of setup and latency. Learn how each approach distributes connections and the trade-offs of dependencies and scalability.
Learn how to secure RSocket apps with ssl and tls, add security dependencies, and enable authentication and authorization for sockets.
secure your rsocket application with ssl/tls by generating a keystore, creating a self-signed certificate, exporting the public certificate, and importing it into a client truststore for trusted connections.
Enable ssl on the spring socket server by configuring spring.socket.server.ssl.enabled, key store type pkcs12, keystore path, password, and key alias in the properties file.
Develop an ssl test using spring boot test to verify tls handshake with a self-signed certificate. Configure a secure tcp client transport and set the client truststore path and password.
Explore simple authentication and authorization with circuit security, leveraging Spring Security concepts, and learn how circuit metadata and dependencies fit into the setup.
Add the required dependencies to the pom file for socket security, including Spring Security, security messaging, and security socket, then perform a Maven re-import and disable SSL in properties.
Create a separate security package with a dummy in-memory user repository backed by a map, wired with a password encoder, to fetch user details by username for role-based access.
Implement a reactive user detail service implementation that wires a user repository, queries by username, converts the result to a user details object, and returns it as a Mono.
Configure rSocket security by building a socket security config with a password encoder and payload socket acceptor interceptor, enabling default or custom authentication and permitting all on setup and requests.
Create a secured map controller to experiment with security, copy and rename an existing controller, and wire a map service secured connection to test the endpoint.
Create a spring boot test and client to verify the permit all security by sending a request via tcp transport to the secured square service and receiving a response.
Configure rsocket authentication by supplying trusted client username and password during setup via metadata. Define mime type and a custom encoder to validate access, illustrating rejected setup with invalid credentials.
Compare setup level authentication and authorization with request level authentication and authorization, and learn when to apply each in a socket-based microservices architecture.
Enforce request-level authentication by requiring a user role and credentials in the metadata from a trusted client, ensuring only users with the user role can access the service.
Implement path-based authorization to restrict routes by admin and user roles, pass credentials via metadata, and test streaming responses in a Spring rSocket microservices setup.
Expose a bean to wire the current user into the rsocket message handler and configure an authentication principal argument resolver to access user details mono.
Enable reactive method security and apply pre authorize annotations to restrict access by role, wiring a security map and validating admin versus user access.
Secure spring rsocket with ssl and tls using self-signed public key certificates. Address handshake errors and implement connection and request level authentication and authorization via configuration or pre authorized annotations.
Build reactive microservices with rSocket and web flex by creating a stock service that emits prices, a user service with cache management, and a trading service for buy-sell flows.
Set up a stock service project with spring initializer and rsocket, ready to emit stock prices for Amazon, Microsoft, and Apple.
Structure the project with a controller, dto, and a service. Create a stock tick data model with code and price using Lombok, then demo emitting stock prices.
Create a stock domain object with price, code, and volatility, exposing getters and an update mechanism that emits new prices based on volatility, ensuring non-negative values.
Create a stock service that emits stock tick data for Amazon, Apple, and Microsoft every two seconds, updating prices with volatility to generate continuous price streams.
Create a stock controller with an autowired stock service, expose a stock ticks endpoint, and return stock price via get stock price, while setting the rsocket server port to 7070.
Test Spring Boot stock service by wiring the builder to a tcp client transport at localhost 7070, emit a flux of stock data, and verify 12 values with step verifier.
Explore building a user balance management system with RSocket, enabling debit and credit on stock trades via the trading service, plus user create, delete, and messaging crud operations with RSocket.
Set up a Spring project for a user service using Spring Initializr, with Maven, Java 11, reactive MongoDB, embedded MongoDB for testing, and Lombok, then import into your development environment.
Organize the user service with controller, entity, repository, service, and util packages; define a user dto (id, name, balance) and transaction enums (credit/debit, completed/failed) plus request/response models.
Implement a reactive user service for management using spring rsocket, exposing get all users, get by id, create, update, and delete operations with flux and mono streams and dto mapping.
Create a reactive user transaction service that processes credit and debit requests, validates users and balances, updates balances via transform, persists changes, and returns a completed or failed transaction response.
Create a user transaction controller, wire the transaction service, and map messages to user.transaction. Use mono and flatMap to pass a transaction request to the service and return the response.
Define a reactive user controller for CRUD operations with spring rsocket, exposing get all, get by id, create, update, and delete endpoints and illustrating request and response streams.
Create a data setup service implementing command line runner to populate three users (Sam, Mike, and Jake) with 10,000 each, saving via the user repository to initialize data for testing.
Test user CRUD in a Spring rSocket microservices setup by configuring a socket requester, running get all users and get single user tests, and validating responses with flux and mono.
Apply crud operations with the requester by implementing create, update, and delete user actions as the assignment, after reviewing the get operation, and refer to the next lecture if unsure.
Execute the assignment by posting a new user, updating the balance with a put, and deleting the user, validating results via get all users in a high performance microservices context.
Pass an operation type as metadata to control CRUD operations via a high level request. Use a metadata route with a mime type to decide get, post, put, or delete.
Configure the server to extract client metadata via a metadata extractor registry, parse mime types, and read the header operation type to map the payload.
Expose web sockets for browser clients by configuring websocket transport and a mapping path to localhost:7071/user service, and include the web flex dependency plus the socket JavaScript client library.
Showcases testing the user transaction service in a Spring Boot RSocket setup, crediting and debiting a random user via a transaction request, with parameterized checks for completed and failed results.
*** Course Project updated for latest Spring Boot 3.2 ***
Welcome to the world of Reactive Socket (rSocket), the blazing-fast binary protocol that has gained significant popularity in recent years, particularly thanks to Netflix. With rSocket, you can develop fully non-blocking asynchronous Microservices while leveraging the power of Reactive-Streams support for client and server communication.
Why choose rSocket?
Enhanced Performance: Operating at layer 5/6, rSocket proves to be considerably faster than traditional HTTP, which operates at network layer 7.
Persistent TCP Connection: rSocket utilizes a persistent TCP connection, allowing bidirectional communication where the server can also call the client.
Reactive Streams Support: Benefit from non-blocking and asynchronous communication between client and server applications through the use of Reactive Streams.
Versatile Interaction Models: Alongside the standard Request-Response model, rSocket offers various interaction models tailored to different use cases.
In this course, you will delve into the intricacies of rSocket, exploring its features and unlocking its potential. You will gain hands-on experience with Spring Integration, rSocket routing, and various interaction models. Topics covered include connection setup, managing connections, cancellation, application flow control, error handling, SSL/TLS, authentication and authorization at both the connection and request levels, load balancing, and more.
Throughout the course, you will engage in practical exercises and real-world scenarios, including the development of microservices, CRUD applications, integration with Spring Data Reactive MongoDB, and the creation of a client-server game.
Join this course to master rSocket, harness its performance advantages, and gain the skills necessary to build high-performance reactive applications using the power of Java Reactive Programming.
Note: This course assumes a familiarity with Java and Reactive Programming concepts.