• Stars
    star
    168
  • Rank 225,507 (Top 5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Multi-instance Reactive WebSocket messaging Chat App demo using Spring Boot 3.x, Java 17 and Redis Pub/Sub

spring-redis-websocket

DockerHub Status License

Multi-instance Reactive Chat App using Spring Boot WebFlux and Redis Pub/Sub

Scalable Java 17 Spring Boot 3.x WebFlux Chat Application to demonstrate use of Reactive Redis Pub/Sub using Reactive WebSocket Handler, without using any external Message Broker like RabbitMQ to sync messages between different instances.

Both JVM based application and Graal Native Image is supported.

Deploy to Heroku

The older non-reactive servlet based spring-redis-websocket application can be found in below:

  1. Spring-Boot 2.3: Java-11 version
  2. Spring-Boot 1.5: Java-8 version

The older reactive spring-boot 2.x (java 11) based spring-redis-websocket application can be found in below:

  1. Spring-Boot 2.4.6: Java-11 Reactive JVM & Graal Native version
  2. Spring-Boot 2.5.2: Java-11 Reactive JVM & Graal Native version

Deploy to Play-with-Docker

Ctrl + Click this button to deploy multiple instances of the spring-redis-websocket load balanced by NGINX:

Deploy to PWD

Installation and Configuration

Pre-requisite for Java Image:

Install and run Redis locally or on Docker.

To run Redis in Docker:

$ docker run -d -p 6379:6379 -e REDIS_PASSWORD=SuperSecretRedisPassword bitnami/redis:6.0.9
Pre-requisite for Graal Native Image:

This application uses Spring Data Redis APIs which doesn't have default Graal hints/config and graal-native image fails to run with errors.

Hence, this application is configured to use GraalVM native image tracing agent allows intercepting reflection, resources or proxy usage on the JVM by running simple Integration Tests which requires Redis.

  1. To run integration test which uses Redis TestContainers so Docker should be configured properly to run Testcontainers
  2. You also need to install GraalVM JDK and native-image component:
    $ sdk install java 22.3.r17-nik         # Using [SDKMAN](https://sdkman.io/jdks) install GraalVM distribution of JDK
    $ sdk use java 22.3.r17-nik
Clone repo:
$ git clone https://github.com/RawSanj/spring-redis-websocket.git

Build and Run the application:

Build and run the spring-redis-websocket application:

$ cd spring-redis-websocket

$ mvn clean package

$ mvn spring-boot:run

Build Graal Native Image of the application:

Build and run the spring-redis-websocket native image:

$ cd spring-redis-websocket

$ mvn -Pnative clean package

$ target/spring-redis-websocket # run the executable binary

Note: Above steps are applicable for Linux only and creates linux executable binary. To create Windows executable there are few additional set-ups required, follow this Steps.

Run in Docker

Build and run the spring-redis-websocket locally in Docker:

Build the JAR file:

$ mvn clean package

Build Docker image:

$ mvn clean spring-boot:build-image

Build Graal Native Docker image:

$ mvn -Pnative clean spring-boot:build-image

Run docker image:

$ docker run -d -p 8080:8080 rawsanj/spring-redis-websocket:3.0.1-webflux # JVM based Docker Image

$ docker run -d -p 8080:8080 rawsanj/spring-redis-websocket:3.0.1-native  # Graal Native Image based Docker Image

Run multiple instances using docker-compose locally

Run multiple instances of spring-redis-websocket locally load balanced via Ngnix connected to redis container in Docker:

$ cd src/main/docker
$ docker-compose up

Or try Play with Docker to quickly setup Docker and run in browser:

  1. Click Create Instance to quickly setup Docker host.
  2. Install git by running:
    $ apk add git --no-cache
  3. Clone the repository:
    $ git clone https://github.com/RawSanj/spring-redis-websocket.git
  4. Run multiple instances of spring-redis-websocket:
    $ cd spring-redis-websocket/src/main/docker
    $ docker-compose up

Run in Kubernetes

Assuming you have a Kubernetes Cluster up and running locally:

$ kubectl apply -f src/main/k8s

Or try Play with Kubernetes to quickly setup a K8S cluster:

  1. Follow the instructions to create Kuberenetes cluster.
  2. Install git by running:
    $ yum install git -y
  3. Clone the repository:
    $ git clone https://github.com/RawSanj/spring-redis-websocket.git
  4. Run multiple instances of spring-redis-websocket load balanced by native Kubernetes Service. All instances connected to a single Redis pod.
    $ cd spring-redis-websocket
    $ kubectl apply -f src/main/k8s

Tech

spring-redis-websocket uses a number of open source projects:

  • Spring Boot - An opinionated framework for building production-ready Spring applications. It favors convention over configuration and is designed to get you up and running as quickly as possible.
  • Spring Data Redis - Spring Data Redis provides easy configuration and access to Redis from Spring applications.
  • Graal Native Image - Native Image is a technology to ahead-of-time compile Java code to a standalone executable, called a native image.
  • Redis - Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.
  • Testcontainers - Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases or anything else that can run in a Docker container.
  • Bootstrap - Bootstrap is an open source toolkit for developing with HTML, CSS, and JS. Custom Bootstrap theme
  • Docker - Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications.
  • NGINX - NGINX is High Performance Load Balancer, Web Server, & Reverse Proxy.
  • Kubernetes - Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

License

Apache License 2.0

Copyright (c) 2023 Sanjay Rawat

More Repositories

1

spring-tiles-sample-app

Spring MVC - Apache Tile - AdminLTE Bootstrap template - Sample Application
Java
33
star
2

java-mail-clients

Send Java Email from GMail, Outlook, Yahoo and Zoho. Demo App to test jHipster tip for Email
Java
26
star
3

springboot-adminlte-thymeleaf

SpringBoot AdminLTE Thymeleaf template with Spring Security - [In Progress].
JavaScript
22
star
4

spring-twitter-stream

Spring Boot - Spring Social - Twitter Stream with Word Cloud and Tweet Search
Java
17
star
5

SOFRepos

Repo for Stack Over Flow Answers and Solutions.
Java
16
star
6

spring-cloud-task-as-k8s-cronjob

Spring Cloud Task Application running as CronJob in Kubernetes - Cron UI: https://github.com/RawSanj/spring-cronjob-currency
Java
9
star
7

boot-kubeless

Spring Boot project for Custom Kubeless Runtime
Shell
8
star
8

SpringRestBatch

Spring Boot-Batch project to read Movies from https://developers.themoviedb.org/3 REST API and store into database.
Java
5
star
9

aws-s3-file-system

AWS S3 File System Application
Java
4
star
10

blogAggr

Spring Boot - Angular - MongoDB complete full-stack webapp for aggregating RSS Feeds.
Java
4
star
11

Angularjs-SharePoint

First AngularJS Project.
JavaScript
2
star
12

spring-cronjob-currency

Spring Boot DataTable Project to view data from https://github.com/RawSanj/spring-cloud-task-as-k8s-cronjob
Java
1
star
13

rawsanj.github.io

Repository for Blogs and Decks
HTML
1
star
14

HeatMap-D3

Interactive Calendar HeatMap in D3.js
JavaScript
1
star
15

Hangfire-MVC-5-Web

This is a demo for how to integrate .NET MVC 5 with Hangfire Scheduler.
JavaScript
1
star
16

aws-service-broker

AWS Open Service Broker written in Kotlin - Offering RDS and S3 Service
Kotlin
1
star
17

kasm-cloud-workspace

KASM Workspace on Oracle Cloud - Ampere Instance
1
star