使用 Spring Boot 3.x、Java 21 和 Redis Pub/Sub 的多实例反应式 WebSocket 消息传递聊天应用程序演示
使用 Spring Boot 3.x、Java 21 和 Redis Pub/Sub 的多实例反应式 WebSocket 消息传递聊天应用程序演示
Scalable Java 21 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 [GraalVM Native Image] is supported. Additionally, the Docker Image for JVM base is available for AMD64 and ARM64 architecture.
The older non-reactive servlet based spring-redis-websocket application can be found in below:
The older reactive spring-boot 2.x (java 11) based spring-redis-websocket application can be found in below:
The older reactive spring-boot 3.2.x (java 17) based spring-redis-websocket application can be found in below:
Ctrl + Click this button to deploy multiple instances of the spring-redis-websocket load balanced by [Traefik]:
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:7.2.3This application uses Spring Data Redis APIs which doesn't have default GraalVM hints/config and graalvm-native image fails to run with errors.
Hence, this application is configured to use GraalVMVM native image tracing agent allows intercepting reflection, resources or proxy usage on the JVM by running simple Integration Tests which requires Redis.
$ sdk install java 21.0.2-graalce # Using [SDKMAN](https://sdkman.io/jdks) install GraalVMVM distribution of JDK
$ sdk use java 21.0.2-graalce$ git clone https://github.com/RawSanj/spring-redis-websocket.gitBuild and run the spring-redis-websocket application:
$ cd spring-redis-websocket
$ mvn clean package
$ mvn spring-boot:runBuild and run the spring-redis-websocket native image:
$ cd spring-redis-websocket
$ mvn -Pnative clean package
$ target/spring-redis-websocket # run the executable binaryNote: 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.
Build the JAR file:
$ mvn clean packageBuild Docker image:
$ mvn clean spring-boot:build-imageBuild GraalVM Native Docker image:
$ mvn -Pnative clean spring-boot:build-imageRun docker image:
$ docker run -d -p 8080:8080 rawsanj/spring-redis-websocket:3.4.4-jvm # JVM based Docker Image
$ docker run -d -p 8080:8080 rawsanj/spring-redis-websocket:3.4.4-native # GraalVM Native Image based Docker ImageRun multiple instances of spring-redis-websocket locally load balanced via [Traefik] connected to redis container in Docker:
$ cd src/main/docker
$ docker-compose up$ apk add git --no-cache$ git clone https://github.com/RawSanj/spring-redis-websocket.git$ cd spring-redis-websocket/src/main/docker
$ docker-compose up$ kubectl apply -f src/main/k8s$ yum install git -y$ git clone https://github.com/RawSanj/spring-redis-websocket.git$ cd spring-redis-websocket
$ kubectl apply -f src/main/k8sspring-redis-websocket uses a number of open source projects:
Apache License 2.0
Copyright (c) 2025 Sanjay Rawat
[Spring Boot]:
[Redis]:
[Runtime]:
[Spring Data Redis]:
[GraalVM Native Image]:
[Testcontainers]:
[Bootstrap]:
[Bootswatch Sketch]:
[Docker]:
[Traefik]:
[Kubernetes]:
[Pub/Sub]:
[WebSocket Handler]:
[Play with Kubernetes]:
[Play with Docker]:
暂无开放 Issues,或尚未同步最近议题。