The goal of this project is to play with RSocket protocol. To do this, we will implement three Spring Boot Java applications: movie-server, movie-client-shell and movie-client-ui. For storage, the reactive NoSQL database MongoDB is used. All streaming of movie events and logging is handled by AOP (Aspect Oriented Programming).
On ivangfr.github.io, I have compiled my Proof-of-Concepts (PoCs) and articles. You can easily search for the technology you are interested in by using the filter. Who knows, perhaps I have already implemented a PoC or written an article about what you are looking for.
- [Medium] RSocket Crypto Server Tutorial
- [Medium] Implementing and Securing a Spring Boot RSocket App using Keycloak for IAM
-
Spring BootJava Web application that exposes REST API endpoints or RSocket routes to managemovies. Movies data are stored in reactiveMongoDB.movie-serverhas the following profiles:-
default- starts REST API on port
8080and usesHTTP.
- starts REST API on port
-
rsocket-tcp- starts REST API on port
8080and usesHTTP. - start RSocket on port
7000and usesTCP.
- starts REST API on port
-
rsocket-websocket- starts REST API on port
8080and usesHTTP. - starts RSocket with mapping-path
/rsocketand usesWebSocket.
- starts REST API on port
-
-
Spring BootShell Java application that has a couple of commands to interact withmovie-server.The picture below shows those commands:
It has the following profiles:
-
default- starts shell with enabled commands to call
movie-serverREST API endpoints usingHTTP.
- starts shell with enabled commands to call
-
rsocket-tcp- starts shell with enabled commands to call
movie-serverREST API endpoints usingHTTP. - starts shell with enabled commands to call
movie-serverRSocket routes usingTCP.
- starts shell with enabled commands to call
-
rsocket-websocket- starts shell with enabled commands to call
movie-serverREST API endpoints usingHTTP. - starts shell with enabled commands to call
movie-serverRSocket routes usingWebSocket.
- starts shell with enabled commands to call
-
-
Spring BootJava Web application that usesThymeleafandWebSocketto show at real-time all the events generated when movies are added, deleted, liked and disliked.movie-client-uihas the following profiles:-
default- starts REST API on port
8081and usesHTTP. - does not connect to
movie-serverthroughRSocket; does not receive movie events.
- starts REST API on port
-
rsocket-tcp- starts REST API on port
8080and usesHTTP. - connects to
movie-serverthroughRSocketusingTCP; receives movie events.
- starts REST API on port
-
rsocket-websocket- starts REST API on port
8080and usesHTTP. - connects to
movie-serverthroughRSocketusingWebSocket; receives movie events.
- starts REST API on port
-
The GIF below shows a user running some commands in movie-client-shell (terminal on the right). The top-right terminal is running movie-server, and the bottom-right terminal runs movie-client-ui. In the background, a browser displays the movie events.
Open a terminal and inside the springboot-rsocket-webflux-aop root folder run:
docker compose up -d-
movie-server
Open a new terminal and, inside the
springboot-rsocket-webflux-aoproot folder, run one of the following profile's command:Profile Command rsocket-tcp ./mvnw clean spring-boot:run --projects movie-server -Dspring-boot.run.profiles=rsocket-tcp rsocket-websocket ./mvnw clean spring-boot:run --projects movie-server -Dspring-boot.run.profiles=rsocket-websocket default ./mvnw clean spring-boot:run --projects movie-server -
movie-client-shell
Open a new terminal and, inside the
springboot-rsocket-webflux-aoproot folder, run the following command to build the executable jar file:./mvnw clean package --projects movie-client-shell -DskipTests
To start
movie-client-shell, run the profile's command you picked to runmovie-serverProfile Commands rsocket-tcp export SPRING_PROFILES_ACTIVE=rsocket-tcp && ./movie-client-shell/target/movie-client-shell-1.0.0.jar rsocket-websocket export SPRING_PROFILES_ACTIVE=rsocket-websocket && ./movie-client-shell/target/movie-client-shell-1.0.0.jar default export SPRING_PROFILES_ACTIVE=default && ./movie-client-shell/target/movie-client-shell-1.0.0.jar -
movie-client-ui
Open a new terminal and, inside the
springboot-rsocket-webflux-aoproot folder, run the profile's command you picked to runmovie-server:Profile Command rsocket-tcp ./mvnw clean spring-boot:run --projects movie-client-ui -Dspring-boot.run.profiles=rsocket-tcp rsocket-websocket ./mvnw clean spring-boot:run --projects movie-client-ui -Dspring-boot.run.profiles=rsocket-websocket default ./mvnw clean spring-boot:run --projects movie-client-ui
-
- In a terminal, make sure you are in the
springboot-rsocket-webflux-aoproot folder. - Run the following script to build the Docker images:
./build-docker-image.sh
- In a terminal, make sure you are in the
-
-
movie-server
Environment Variable Description MONGODB_HOSTSpecify host of the Mongodatabase to use (defaultlocalhost)MONGODB_PORTSpecify port of the Mongodatabase to use (default27017) -
movie-client-shell
Environment Variable Description MOVIE_SERVER_HOSTSpecify host of the movie-serverto use (defaultlocalhost) -
movie-client-ui
Environment Variable Description MOVIE_SERVER_HOSTSpecify host of the movie-serverto use (defaultlocalhost)
-
-
- In a terminal, make sure you are inside the
springboot-rsocket-webflux-aoproot folder. - Run following command:
- rsocket-tcp
./start-server-and-ui.sh rsocket-tcp && ./start-shell.sh rsocket-tcp - rsocket-websocket
./start-server-and-ui.sh rsocket-websocket && ./start-shell.sh rsocket-websocket - default
./start-server-and-ui.sh && ./start-shell.sh
- rsocket-tcp
- In a terminal, make sure you are inside the
| Application | Type | Transport | URL |
|---|---|---|---|
| movie-server | RSocket | TCP | tcp://localhost:7000 |
| movie-server | RSocket | WebSocket | ws://localhost:8080/rsocket |
| movie-server | REST | HTTP | http://localhost:8080 |
| movie-client-ui | Website | HTTP | http://localhost:8081 |
Note: you can see the clients connected to
movie-serverby calling theinfoactuator endpoint.curl -i localhost:8080/actuator/info
Note: to run the commands below, you must start
movie-serverandmovie-client-shellwithrsocket-tcporrsocket-websocketprofiles.
-
Open a browser and access
movie-client-uiat http://localhost:8081 -
Go to
movie-client-shellterminal. -
Add a movie using RSocket (
Request-Response):add-movie-rsocket --imdb aaa --title "RSocketland"It should return:
{"imdb":"aaa","title":"RSocketland","lastModifiedDate":"2020-07-20T12:43:39.857248","likes":0,"dislikes":0}A
+action should be displayed inmovie-client-ui. -
Add a movie using REST:
add-movie-rest --imdb bbb --title "I, REST"It should return:
{"imdb":"bbb","title":"I, REST","lastModifiedDate":"2020-07-20T12:44:13.266657","likes":0,"dislikes":0}A
+action should be displayed inmovie-client-ui. -
Send a like to
RSocketlandmovie using RSocket (Fire-And-Forget):like-movie-rsocket --imdb aaa
It should return:
Like submittedA
thumbs-upaction should be displayed inmovie-client-ui. -
Get all movies using RSocket (
Request-Stream):get-movies-rsocket
It should return:
{"imdb":"aaa","title":"RSocketland","lastModifiedDate":"2020-07-20T12:56:34.565","likes":1,"dislikes":0} {"imdb":"bbb","title":"I, REST","lastModifiedDate":"2020-07-20T12:56:26.846","likes":0,"dislikes":0} -
Select movies using RSocket (
Channel).select-movies-rsocket --imdbs aaa,bbb
It should return:
| IMDB: aaa | TITLE: RSocketland | LIKES: 1 | DISLIKES: 0 | | IMDB: bbb | TITLE: I, REST | LIKES: 0 | DISLIKES: 0 | -
Delete movie
RSocketlandusing RSocket (Request-Response) and movieI, RESTusing REST.delete-movie-rsocket --imdb aaa delete-movie-rest --imdb bbb
It should return, as response, the IMDB of the movies.
A
-actions should be displayed inmovie-client-ui. -
Simulation
There are two scripts that contain some commands to add, retrieve, like, dislikes and delete movies. One uses REST, and the other uses RSocket to communicate with
movie-server. At the end of the script execution, it's shown theExecution Timeinmilliseconds.-
If you are running the applications with Maven:
- REST
script ../src/main/resources/simulation-rest.txt
- RSocket
script ../src/main/resources/simulation-rsocket.txt
- REST
-
If you are running the applications as Docker containers:
- REST
script /workspace/BOOT-INF/classes/simulation-rest.txt
- RSocket
script /workspace/BOOT-INF/classes/simulation-rsocket.txt
- REST
-
-
MongoDB
Find all movies:
docker exec -it mongodb mongosh moviedb db.movies.find()
Type
exitto get out ofMongoDBshell.
- To stop
movie-client-shell, go to the terminal where it is running and typeexit. - To stop
movie-serverandmovie-client-ui:- If you start them with Maven, go to the terminals where they are running and press
Ctrl+C. - If you start them as Docker containers, go to a terminal and, inside the
springboot-rsocket-webflux-aoproot folder, run the following command:./stop-server-and-ui.sh
- If you start them with Maven, go to the terminals where they are running and press
- To stop and remove docker compose
mongodbcontainer, network and volumes, go to a terminal and, inside thespringboot-rsocket-webflux-aoproot folder, run the command below:docker compose down -v
To remove the Docker images created by this project, go to a terminal and, inside the springboot-rsocket-webflux-aop root folder, run the script below:
./remove-docker-images.sh- https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#rsocket
- https://spring.io/blog/2020/05/12/getting-started-with-rsocket-servers-calling-clients
- https://grapeup.com/blog/reactive-service-to-service-communication-with-rsocket-introduction/
The autocomplete is not working when we run movie-client-shell as Docker container.



