https://github.com/vpavic/samples-spring-sse-redis
Samples: Spring Server-Sent Events with Redis
https://github.com/vpavic/samples-spring-sse-redis
java redis samples server-sent-events spring-boot spring-data-redis spring-framework
Last synced: 6 months ago
JSON representation
Samples: Spring Server-Sent Events with Redis
- Host: GitHub
- URL: https://github.com/vpavic/samples-spring-sse-redis
- Owner: vpavic
- License: apache-2.0
- Created: 2021-11-30T22:41:34.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-29T23:00:06.000Z (about 2 years ago)
- Last Synced: 2024-04-30T23:51:11.127Z (about 2 years ago)
- Topics: java, redis, samples, server-sent-events, spring-boot, spring-data-redis, spring-framework
- Language: Java
- Homepage:
- Size: 284 KB
- Stars: 5
- Watchers: 4
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE.txt
Awesome Lists containing this project
README
= Samples: Spring Server-Sent Events with Redis
image:https://github.com/vpavic/samples-spring-sse-redis/actions/workflows/build.yml/badge.svg["Build", link="https://github.com/vpavic/samples-spring-sse-redis/actions/workflows/build.yml"]
This repository contains sample applications that showcase Spring Framework's support for https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events[server-sent events] backed by https://redis.io/topics/pubsub[Redis Pub/Sub].
The name of each sample application tells the web stack it's based on, and optionally the data access paradigm it uses to interact with Redis:
* `sample-mvc-imperative`: Spring MVC Sample with Imperative Spring Data Redis
* `sample-mvc-reactive`: Spring MVC Sample with Reactive Spring Data Redis
* `sample-webflux`: Spring WebFlux Sample (with Reactive Spring Data Redis)
== Getting Started
=== Requirements
Java 11 is required to run the samples.
The project is built using Gradle and uses https://docs.gradle.org/current/userguide/gradle_wrapper.html[Gradle Wrapper] to take care of downloading the appropriate Gradle version.
=== Running the Samples
Each sample is a Spring Boot based application that can be started:
* using the `bootRun` task of the appropriate sample application
* from IDE by running sample application's main class
By default, all samples start web server on port `8080` and attempt to connect to Redis running locally at port `6379`.
In order to change those defaults, use appropriate Spring Boot configuration properties.
All the samples expose the following two HTTP endpoints:
* `POST /topics/{name:[a-z]{2}}`
+
Generates an event and publishes it to the specified Redis channel.
For example, the following request will result in event being published to channel named `aa`:
+
[source,sh]
----
$ curl -s -X POST http://localhost:8080/topics/aa
----
* `GET /topics/{name:[a-z]{2}}`
+
Subscribes to server-sent events published to the specified Redis channel.
The following request will subscribe to events published to channel named `aa`:
+
[source,sh]
----
$ curl -N http://localhost:8080/topics/aa
----
==== Spring MVC Sample with Imperative Redis
This sample uses Spring MVC and a traditional imperative Redis using Jedis driver.
[source,sh]
----
$ ./gradlew :sample-mvc-imperative:bootRun
----
==== Spring MVC Sample with Reactive Redis
This sample uses Spring MVC combined with reactive Redis using Lettuce driver.
[source,sh]
----
$ ./gradlew :sample-mvc-reactive:bootRun
----
==== Spring WebFlux Sample
This sample uses Spring WebFlux, naturally combined with reactive Redis using Lettuce driver.
[source,sh]
----
$ ./gradlew :sample-webflux:bootRun
----
=== Building from Source
The project can be built the `build` task:
[source,sh]
----
$ ./gradlew build
----
== Related Issues
- https://github.com/spring-projects/spring-data-redis/issues/2209[spring-projects/spring-data-redis#2209]
- https://github.com/spring-projects/spring-data-redis/issues/2229[spring-projects/spring-data-redis#2229]
- https://github.com/spring-projects/spring-data-redis/issues/2386[spring-projects/spring-data-redis#2386]
- https://github.com/lettuce-io/lettuce-core/issues/705[lettuce-io/lettuce-core#705]
- https://github.com/cloudfoundry/java-buildpack-memory-calculator/issues/20[cloudfoundry/java-buildpack-memory-calculator#20]