This is a demo project to demonstrate the power of spring boot http session stored inside redis.
Benefit of using redis as a persistence session storage:
- The application layer will get some headroom as redis will be used to offload sessions
- Server restarts won't affect the session and user won't get logged out
- We can run multiple instance of the server and load balance user request without user getting logged out while routing to different instance
- Java version
17 - You will need
redisto be running in it's default host & port (change them to your liking fromapplication.propertiesfile if you want)
- Install
nginxfor your operation system - Take a back up of you existing
ngingx.conffile if you have one - Replace the old
ngingx.confwith the file present in the root directory of this project - Now run two separate instance of the application one in port
8080and other in port8081- Open one command prompt and past this command to run in port
8080mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8080" - Open another command prompt and paste this command to run in port
8081mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8081"
- Open one command prompt and past this command to run in port
Now visit
http://localhost
You will need to login. There are two in memory user:
- UserName:
userPassword:passwordAuthorized Endpoints:/ - UserName:
adminPassword:passwordAuthorized Endpoints:/&/admin
If you hit and keep refresh page on / endpoint. Now and go back and forth between the two opened terminal prompt now
you will find out that user hit will be printed on different terminal prompt each time which will cycle through the two prompt.
Which proves the application is getting load balanced without logging out the user